2015-05-29 67 views
1

擴展名不同的多個文件我有不同的擴展名一堆文件,我想在他們的名字的末尾添加一個後綴:重命名的Linux

Fe2-K-D4.rac 
Fe2-K-D4.plo 
Fe2-K-D4_iso.xy 
... 

Fe2-K-D4-4cc8.rac 
Fe2-K-D4-4cc8.plo 
Fe2-K-D4-4cc8_iso.xy 
... 

我讀了一些關於使用重命名工具更改擴展的文章,但我不知道如何更改名稱並保持相同的擴展名(我是最近的linus用戶)。

感謝所有幫助

回答

1

使用Extract filename and extension in Bash,我會說:

for file in * 
do 
    extension="${file##*.}" 
    filename="${file%.*}" 
    mv "$file" "${filename}-4cc8.${extension}" 
done 

這個循環遍歷所有的文件,它的名字和擴展名,然後將它(即,將其重命名)移動到給定的名稱在擴展之前具有額外的-4cc8值。

+1

它就像一個魅力! 祝你有個美好的一天,你做了我的。 – Portecochon

1

使用rename

rename 's/[.]([^.]+)$/-4cc8.$1/' * 

s/[.]([^.]+)$/-4cc8.$1/perl expression of the form s/PATTERN/REPLACEMENT/ 告訴rename做一個全球性的substition。

[.]([^.]+)$是一個正則表達式模式具有以下含義:

[.]  match a literal period 
(  followed by a group 
    [  containing a character class 
    ^. composed of anything except a literal period 
    ]+ match 1-or-more characters from the character class 
)  end group 
$  match the end of the string. 

的替換模式,-4cc8.$1,講述rename與文字-4cc8.後跟文本相匹配的第一組中以替換匹配的文本,即任何隨後文字時期。