批量改文件名

要求:把"-sample"去掉
[root@73 hj]# ls
check_all_local_disks.cfg-sample    check_nrpe.cfg-sample    check_nwstat.cfg-sample

方法一、
[root@73 hj]# for i in $(ls .);do mv $i $(echo $i|sed 's/-sample//g');done
[root@73 hj]# ls
check_all_local_disks.cfg    check_nrpe.cfg    check_nwstat.cfg

方法二、
[root@73 hj]# ls
check_all_local_disks.cfg-sample    check_nrpe.cfg-sample    check_nwstat.cfg-sample
[root@73 hj]# ls|awk -F"-sample" '{print "mv "$0" "$1""}'|sh
[root@73 hj]# ls
check_all_local_disks.cfg    check_nrpe.cfg    check_nwstat.cfg

方法三、
[root@73 hj]# ls
check_all_local_disks.cfg-sample    check_nrpe.cfg-sample    check_nwstat.cfg-sample
[root@73 hj]# rename "-sample" "" *
[root@73 hj]# ls
check_all_local_disks.cfg    check_nrpe.cfg    check_nwstat.cfg

注:
[root@73 hj]# ls
check_all_local_disks.cfg    check_nrpe.cfg    check_nwstat.cfg
[root@73 hj]# rename "cfg" "cfg-aa" *
[root@73 hj]# ls
check_all_local_disks.cfg-aa    check_nrpe.cfg-aa    check_nwstat.cfg-aa

你可能感兴趣的:(职场,awk,rename,休闲,sed批量改文件名)