Batch file name modification in Linux
Sometimes we have a directory. The following file names need to be re-ordered
For example: The following 10 students completed the script, now need to change the finish to ing
[[email protected] test]# Touch student_{01..10}_finish.sh[[email protected] test]# ls student_*student_01_finish.sh Student_03_finish.sh Student_05_f
student_02_finish.sh student_04_finish.sh student_06_finish.sh student_08_finish.sh student_10_finish.sh
Method 1:sed
For f in ' LS student_* '; Do echo $f | MV $f ' sed ' s#finish#ing#g ';d one
Method 2:awk string concatenation method (in pass to bash)
Test:
[Email protected] test]# echo student_05_finish.sh | Awk-f ' Finish ' {print "MV" $ "" $ "ing" $ "student_05_finish.sh student_05_ing.sh
Batch Execution
[[email protected] test]# for f in ' ls student* ';d o echo $f | Awk-f ' Finish ' {print ' mv "$" "$" ing "$";d One | Bash[[email protected] test]# ls student_*student_01_ing.sh student_03_ing.sh student_05_ing.sh student_07_ing.sh Stud ent_09_ing.shstudent_02_ing.sh student_04_ing.sh student_06_ing.sh student_08_ing.sh student_10_ing.sh
Or:
For f in ' ls student* ';d o echo $f | MV $f ' awk-f ' Finish ' {print $ ' ing ' $ ';d one
Method Three: Rename command, professional processing batch modified file name of the Linux command
Usage: Man rename
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7F/4C/wKiom1cY6HGzCQvcAAAveZ7PjPE296.png "title=" Rename.png "alt=" Wkiom1cy6hgzcqvcaaavez7pjpe296.png "/>
[Email protected] test]# rename "Finish" "ing" student_*[[email protected] test]# ls student_*student_01_ing.sh student_ 03_ing.sh student_05_ing.sh student_07_ing.sh student_09_ing.shstudent_02_ing.sh student_04_ing.sh student_06_ ing.sh student_08_ing.sh student_10_ing.sh
This article is from the "Tridewah operation and maintenance work Road" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1766448
Batch file name modification in Linux