Shell command Bulk modify picture filename _linux Shell

Source: Internet
Author: User

Company colleagues today to find me help modify the filename, I see, well, hundreds of files to rename, file name format is _01.png _02.png so in turn, colleagues asked the front of the "_" to remove, fortunately, the request is simple, did not let me change to another name.

An order to fix:


Copy Code code as follows:

For i in ' LS _*.png '; Do mv "$i" "echo" $i "|awk-f ' _0 '" {print $0 "$}"; Done


If you want to get rid of the _0, so write:


Copy Code code as follows:

For i in ' LS _*.png '; Do mv "$i" ' echo ' $i ' |awk-f ' _0 ' {print $1,$2} '; Done


OK, this is done, and then give you some other similar orders, the following command I did not verify that there are problems do not look for me oh.

*_ the format? JPG file changed to *_0? Jpg:


Copy Code code as follows:

For i in ' ls *_?. JPG '; Do mv "$i" ' echo "$i" |awk-f ' _ ' "{print $" _0 "$}"; Done


Change the first three letters of a filename into vzomik:


Copy Code code as follows:

For i in ' ls '; Do mv-f "$i" ' echo ' $i ' |sed ' s/^.../vzomik/'; Done


Turn the four letters of the filename into vzomik:


Copy Code code as follows:

For i in ' ls '; Do mv-f "$i" ' echo ' $i ' |sed ' s/....$/vzomik/'; Done

Related Article

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.