批量改名的多种方法stu_3_finished.jpg 去掉finished,stu_{1..20}_finished.jpg
方法一:rename修改文件名
rename "finished" "" *.jpg
[root@ob1 scripts]# rename "finished" "" *.jpg
stu_3_finished.jpg
stu_3_.jpg
方法二:截取字符串的方法去除finished 后面的内容结尾添加jpg
[root@ob1 scripts]# vi tmp.sh
#!/bin/bash
for i in `ls *.jpg`
do
mv $i ${i%finished*}.jpg
done
方法三:sed直接修改
[root@ob1 scripts]# ls *.jpg|sed -rn 's#(.*)finished(.*)#mv & \1\2#gp'
mv stu_3_finished.jpg stu_3_.jpg
mv stu_4_finished.jpg stu_4_.jpg
[root@ob1 scripts]# ls *.jpg|sed -rn 's#(.*)finished(.*)#mv & \1\2#gp'|bash
[root@ob1 scripts]# ls
方法四awk方法拼接字符串
[root@ob1 scripts]# ls *.jpg|awk -F"finished" '{print "mv",$0,$1$2}'
mv stu_3_finished.jpg stu_3_.jpg
mv stu_4_finished.jpg stu_4_.jpg
[root@ob1 scripts]# ls *.jpg|awk -F"finished" '{print "mv",$0,$1$2}'|bash
[root@ob1 scripts]# ls
stu_3_.jpg stu_4_.jpg