Linux文件單個重命名一般用mv命令,集體重命名很多人自己寫一個簡單腳本,但是其實Linux的rename命令可以簡單實現絕大多數的重命名任務。
man rename結果如下:
NAME
rename - Rename files
SYNOPSIS
rename from to file...
DESCRIPTION
rename will rename the specified files by replacing the first occurrence of from in their name by to.
For example, given the files foo1, ..., foo9, foo10, ..., foo278, the commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ..., foo278.
And
rename .htm .html *.htm
will fix the extension of your html files.
比如我有三個文件:
hs_ok_all_200911.txt
hs_ok_all_a.txt
hs_ok_all_b.txt
我需要將所有的hs_ok_all改為hs
則使用
rename hs_ok_all hs hs_ok_all_*
即可。
所以rename的第一個參數是要改的部分, 第二個參數是改後的結果,第三個參數是需要改的文件(含通配符)。