rename批量修改文件名

批量改名:

如文件,批量修改,把hello去掉
[root@localhost wang]# ll
-rw-r--r-- 1 root root 0 5月 14 02:36 a.hello.txt
-rw-r--r-- 1 root root 0 5月 14 02:36 b.hello.txt

方法一:
使用sed

for i in `ls *.txt`;do mv $i `echo $i|sed 's/hello.//g'`;done

[root@localhost wang]# ll
总用量 0
-rw-r--r-- 1 root root 0 5月 14 02:46 a.txt
-rw-r--r-- 1 root root 0 5月 14 02:46 b.txt


方法二:

使用awk
for i in `ls *.txt`;do mv $i `echo $i | awk -F '.hello' '{print $1 $2}'`;done

方法三:

专业改名工具:rename
语法
rename from to file
from:你要改的内容
to:改成什么内容
file:对什么文件修改
案例:
[root@localhost wang]# ll
-rw-r--r-- 1 root root 0 5月 14 02:36 a.hello.txt
-rw-r--r-- 1 root root 0 5月 14 02:36 b.hello.txt

[root@localhost wang]# rename .hello "" *.txt ##改为

[root@localhost wang]# ll
总用量 0
-rw-r--r-- 1 root root 0 5月 14 02:36 a.txt
-rw-r--r-- 1 root root 0 5月 14 02:36 b.txt

总结: rename 内容 内容 文件

原文地址:https://www.cnblogs.com/chuangcc/p/11228712.html