Linux 使用rename命令批量重命名文件
命令格式:
Usage: rename [-v] [-n] [-f] perlexpr [filenames]
参数说明:
v 显示文件重命名的细节
n 不执行重命名,但会模拟执行重命名,并显示会出现的情况,例如是否会有同名文件冲突等。在重命名前测试很有用。
f 强制覆盖同名文件
- 批量更改文件扩展名
ls1.txt2.txt3.txt4.txt rename ‘s/.txt/.ext/’ *
$ ls
1.ext 2.ext 3.ext 4.ext - 批量删除文件扩展名
ls1.txt2.txt3.txt4.txt rename ‘s/.txt//’ *
$ ls
1 2 3 4 - 批量添加文件扩展名
ls1234 rename 's/ /.txt/′∗ ls
1.txt 2.txt 3.txt 4.txt - 按自己的方式批量重命名文件
ls1.txt2.txt3.txt4.txt rename ‘s/^/hello_/’ *.txt
$ ls
hello_1.txt hello_2.txt hello_3.txt hello_4.txt