Shell batch renaming

Source: Internet
Author: User
========================================================== ========================================================== ======== RENAME [-V] [-N] [-F] perlexpr [files]-V, -- verboseverbose: Print names of files successfully renamed. -N, -- no-actno action: show what files wocould have been renamed. -F, -- forceforce: overwrite existing files. simple RENAME command: replace rename "s/AA/" * // replace AA in the file name with AA to change the file suffix rename "s /. html /. PHP/"* // change the. html suffix. PHP suffix batch add file suffix rename "s/$ /. TXT/"* // delete all file names at the end of the TXT batch rename" s /. TXT // "* // Delete All TXT files whose names end with. txt
One command: Rename "s/. jpg/. jpg.
========================================================== ========================================================== ======== Usage:
1. Place all the files you want to rename in the same folder, Run "ls-L> oldnames", and then "VI oldnames". This is probably the case:
Total spent 3 yanpeng 4096 sep 17 appdrwxrwxr-x 2 yanpeng 4096 May 19 2009 bindrwxrwxr-x 2 yanpeng 8192 Jan 26 docpay2. enter "Ctrl + V" to move the cursor, select the heap of content to be deleted, which is actually the columns before the file name. Enter "D" and the obtained file is roughly
Appbindocpay3. Delete the empty line of the first line, save and exit VI, and then "CP oldnames newnames ".
4. Modify the newnames file to be renamed as the new file name.
5. Place the change_name.sh script in your folder and run./change_name.sh. (Note that you have the execution permission. Add the execution permission to chmod A + x change_name.sh)
Change_name.sh script content, copy it, save it, and use it

#! /Bin/sh
Oldnames = 'oldnames' newnames = 'newnames'
Fileline = 'sed-n' $ = '$ oldnames' echo $ fileline
Index = 1 while [$ index-Le $ fileline] dooldname = 'sed-n "$ {index} p" $ oldnames 'newname = 'sed-n "$ {index} p "$ newnames 'mv $ oldname $ newnameindex = 'expr $ index + 1' done ================== ========================================================== ========================================= self-conversion: http://blog.chinaunix.net/uid-23915916-id-2653226.html
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.