问题:将文件名中的finished去掉:
创建测试文件:
[root@node1 mod_file_name]# cat a.txt
stu_102999_2_finished.jpg
stu_102999_3_finished.jpg
stu_102999_4_finished.jpg
stu_102999_5_finished.jpg
[root@node1 mod_file_name]# touch `cat a.txt | tr "\n" " "`
[root@node1 mod_file_name]# ll
total 4
-rw-r--r-- 1 root root 104 Aug 24 09:39 a.txt
-rw-r--r-- 1 root root 0 Aug 24 09:51 stu_102999_2_finished.jpg
-rw-r--r-- 1 root root 0 Aug 24 09:51 stu_102999_3_finished.jpg
-rw-r--r-- 1 root root 0 Aug 24 09:51 stu_102999_4_finished.jpg
-rw-r--r-- 1 root root 0 Aug 24 09:51 stu_102999_5_finished.jpg
方法一:
[root@node1 mod_file_name]# for n in `ls *.jpg`; do mv $n `echo $n|sed 's#finished##g'`;done
查看:
[root@node1 mod_file_name]# ll
-rw-r--r-- 1 root root 0 Aug 24 09:40 stu_102999_2_.jpg
-rw-r--r-- 1 root root 0 Aug 24 09:40 stu_102999_3_.jpg
-rw-r--r-- 1 root root 0 Aug 24 09:40 stu_102999_4_.jpg
-rw-r--r-- 1 root root 0 Aug 24 09:40 stu_102999_5_.jpg
方法二:
[root@node1 test]# ls
stu_102999_2_finished.jpg stu_102999_3_finished.jpg stu_102999_4_finished.jpg stu_102999_5_finished.jpg
[root@node1 test]# ls | awk -F "finished" '{print "mv " $0" "$1$2}'| bash
[root@node1 test]# ls
stu_102999_2_.jpg stu_102999_3_.jpg stu_102999_4_.jpg stu_102999_5_.jpg
方法三:
[root@node1 test]# ls
stu_102999_2_finished.jpg stu_102999_3_finished.jpg stu_102999_4_finished.jpg stu_102999_5_finished.jpg
[root@node1 test]# rename finished "" *.jpg
[root@node1 test]# ll
total 0
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_2_.jpg
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_3_.jpg
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_4_.jpg
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_5_.jpg
[root@node1 test]# rename jpg html stu*
[root@node1 test]# ll
total 0
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_2_.html
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_3_.html
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_4_.html
-rw-r--r-- 1 root root 0 Aug 24 10:35 stu_102999_5_.html
2016-11-16
文件名批量更改
评论
发表评论
姓 名: