2008年(91)
分类: LINUX
2008-03-23 21:00:52
rename - renames multiple files
也就是说rename专门用于成批的改具有相同特征的一类文件的名字。
"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
To translate uppercase names to lower, you'd use
rename 'y/A-Z/a-z/' *
实战:aaa3_2007-12-11_bbb3.log
aaa1_2007-12-11_bbb2.log
aaa1_2007-12-11_bbb1.log
要改成
aaa3_2007-12-15_bbb3.log
aaa1_2007-12-15_bbb2.log
aaa1_2007-12-15_bbb1.log
rename 's/12\-11/12\-15/' *.log即可实现
如文件夹中有这些文件foo1, ..., foo9, foo10, ..., foo278,如果使用
rename foo foo0 foo?
则它只会把foo1到foo9的文件重命名为foo1到foo9,因为?通配符只能替代单个字符,所以被重命名的文件只是有4个字符长度名称的文件,文件名中的foo被替换为foo0。
再继续使用
rename foo foo0 foo??
则文件夹中的foo01到foo99的,因为通配符?的使用,所以只重命名5个字符长度名称的文件,文件名中的foo被替换为foo0。
如果再继续使用
rename foo foo0 foo*
所有以foo开头的文件都被重命名了,文件名中的foo被替换为foo0。