源文件;
[root@test_machine fuzj]# ls
fuzj-1.txt fuzj-2.txt fuzj-3.txt fuzj-4.txt fuzj-5.txt fuzj-6.txt
方法1.
[root@test_machine fuzj]# for name in `ls *` ; do mv $name `echo $name| sed 's/fuzj/fuzengjie/g'` ;done
[root@test_machine fuzj]# ls
fuzengjie-1.txt fuzengjie-3.txt fuzengjie-5.txt
fuzengjie-2.txt fuzengjie-4.txt fuzengjie-6.txt
方法2.
[root@test_machine fuzj]# for name in `ls *` ;do echo $name| awk -F"-" '{print "mv " $0 " fuzj-" $2 }'|bash ; done
[root@test_machine fuzj]# ls
fuzj-1.txt fuzj-2.txt fuzj-3.txt fuzj-4.txt fuzj-5.txt fuzj-6.txt
注意print里面的空格
方法3.
[root@test_machine fuzj]# for name in `ls *` ; do mv $name ${name/fuzj/fuzengjie} ; done
[root@test_machine fuzj]# ls
fuzengjie-1.txt fuzengjie-2.txt fuzengjie-3.txt fuzengjie-4.txt fuzengjie-5.txt fuzengjie-6.txt
方法4.
[root@test_machine fuzj]# rename fuzengjie fuzj *
[root@test_machine fuzj]# ls
fuzj-1.txt fuzj-2.txt fuzj-3.txt fuzj-4.txt fuzj-5.txt fuzj-6.txt