操作系统 Centos7
1. rename 命令批量改文件名
C版本:
rename 原字符串 新字符串 文件名
rename .jpg .png *
Perl版本:支持正则表达式
rename ‘s/原字符串/新字符串/’ 文件名
rename ‘s/$/\.bak/’ * # 把所有文件加扩展名 .bak
其中 Centos 默认是 C 版本 Ubuntu 默认是 Perl 版本,Centos 需要自己安装 Perl 版本命令是 prename
[root@node01 test]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
[root@node01 test]# yum -y install prename
[root@node01 test]# ls
3.11.18.2 3.12.18.1 3.15.18.1 3.20.18.1 3.2.18.1 3.2.18.7 3.24.18.1 3.27.18.1 3.3.18.1 3.33.18.2 3.36.18.2 3.4.18.2 3.44.18.2 3.5.18.2 3.54.18.1 3.63.18.1 3.7.18.2 3.75.18.2
[root@node01 test]# rename 's/./_/' *
[root@node01 test]# ls
3.11.18.2 3.12.18.1 3.15.18.1 3.20.18.1 3.2.18.1 3.2.18.7 3.24.18.1 3.27.18.1 3.3.18.1 3.33.18.2 3.36.18.2 3.4.18.2 3.44.18.2 3.5.18.2 3.54.18.1 3.63.18.1 3.7.18.2 3.75.18.2
[root@node01 test]# prename 'y/./_/' 3.*.18.*
[root@node01 test]# ls
3_11_18_2 3_12_18_1 3_15_18_1 3_20_18_1 3_2_18_1 3_2_18_7 3_24_18_1 3_27_18_1 3_3_18_1 3_33_18_2 3_36_18_2 3_4_18_2 3_44_18_2 3_5_18_2 3_54_18_1 3_63_18_1 3_7_18_2 3_75_18_2
[root@node01 test]#