![[파일 이름].mp4를 모두 찾아 [파일 이름].audio [중복] 이름을 바꿉니다.](https://linux55.com/image/76054/%5B%ED%8C%8C%EC%9D%BC%20%EC%9D%B4%EB%A6%84%5D.mp4%EB%A5%BC%20%EB%AA%A8%EB%91%90%20%EC%B0%BE%EC%95%84%20%5B%ED%8C%8C%EC%9D%BC%20%EC%9D%B4%EB%A6%84%5D.audio%20%5B%EC%A4%91%EB%B3%B5%5D%20%EC%9D%B4%EB%A6%84%EC%9D%84%20%EB%B0%94%EA%BF%89%EB%8B%88%EB%8B%A4..png)
그래서 파일의 오디오를 사용하여 두 개의 영화를 함께 추가하는 스크립트가 있습니다 $1.audio
. 내가 하고 싶은 일은 디렉터리에 있는 모든 파일의 이름을 다음과 같이 바꾸는 것입니다.
*.mp4
도착하다:
*.audio
원본 파일 이름을 유지하세요.
답변1
이 명령을 사용할 수 있습니다 rename
. 이식성이 없지만 배포판에 따라 다른 형태로 존재합니다.
CentOS/RHEL 및 Fedora의 경우:
rename .mp4 .audio *.mp4
해야 할 것. man rename
CentOS 6 부터 :
SYNOPSIS
rename from to file...
rename -V
DESCRIPTION
rename will rename the specified files by replacing the first occur-
rence of from in their name by to.
Ubuntu 및 Debian 변형의 경우:
rename 's/\.mp4$/.audio/' *.mp4
그것은 이루어져야합니다. man rename
Ubuntu 14.04 부터 :
SYNOPSIS
rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]
DESCRIPTION
"rename" renames the filenames supplied according to the rule specified
as the first argument. The perlexpr argument is a Perl expression
which is expected to modify the $_ string in Perl for at least some of
the filenames specified. If a given filename is not modified by the
expression, it will not be renamed. If no filenames are given on the
command line, filenames will be read via standard input.
For example, to rename all files matching "*.bak" to strip the
extension, you might say
rename 's/\.bak$//' *.bak
답변2
이상한 이름의 파일을 처리하는 빠르고 이식 가능한 솔루션은 다음과 같습니다.
find . -name "*.mp4" -exec sh -c 'for i do mv -- "$i" "${i%.mp4}.audio"; done' sh {} +
답변3
다음 for
루프를 사용하세요.
for f in *; do
[ -f "$f" ] && mv -v -- "$f" "${f%.mp3}.audio"
done
for i in *
현재 작업 디렉터리(점 파일 제외)의 모든 파일과 디렉터리를 반복하고 현재 처리된 파일을$f
[ -f "$f" ]
일반 파일인지 확인하세요.mv -v
파일 이름 바꾸기(--
파일 이름은 인수로 잘못 해석되지 않습니다)${f%.mp3}.audio
.mp3
확장자를 제거 하고.audio
확장자를 추가합니다(매개변수 확장)
답변4
당신은 그것을 사용할 수 있습니다
for file in `ls *.mp4`; { mv $file `echo $file | sed 's/.mp4/.audio/g'`; }