Linux Shell文件集体重命名的方法


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的第一个参数是要改的部分, 第二个参数是改后的结果,第三个参数是需要改的文件(含通配符)。

相关内容