Batch file name modification in Linux

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.