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