Linux batch rename files

Source: Internet
Author: User
Objective: To rename several files in batches. These files have common features, such as having the same letters or having no common features. to rename these files in a unified manner, modify the characters at the same position. 1. I want to change the first letter of their names to "q", and the others will not change. [Root @ pps mailqueue] # for I in 'LS'; do mv-f $ I 'echo $ I | sed's/^./q/''; done ----------------------------------------
Or write a script to make it clearer: for file in 'LS'
Do
Newfile = 'echo $ I | sed's/^./q /''
Mv $ file $ newfile
Done
---------------------------------------- 2. Change the first five letters to zhaozh. [Root @ pps mailqueue] # for I in 'LS'; do mv-f $ I 'echo $ I | sed's/^ ..... /zhaozh/''; done 3. Change the last five letters to "snail Il ".[Root @ pps mailqueue] # for I in 'LS'; do mv-f $ I 'echo $ I | sed's /..... $/snail il/''; done 4. Add _ hoho _ [Root @ pps mailqueue] # for I in 'LS'; do mv-f $ I 'echo "_ hoho _" $ I '; done 5. Change all lowercase letters to uppercase letters.[Root @ pps mailqueue] # for I in 'LS'; do mv-f $ I 'echo $ I | tr a-z A-Z '; done

Alas, five examples are given. In the end, the idea of "for loop + combined command processing" is used to batch rename objects.

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.