Batch file name modification under Linux (rename)

Source: Internet
Author: User
Tags perl script

Original address: http://blog.csdn.net/sea_shore/article/details/6102437

1.rename Command Batch modified file name, in fact, Linux can use other methods to batch change the file name, but rename is too convenient

For example, change all the tables to cdb1_* to cdb_*.
In this directory
Only need # rename ' cdb1 ' CDB ' *

Used to write a for loop to do ... Think about how silly ah, hehe

Rename also has more features that suggest man rename under

From:http://www.hao32.com/unix-linux/42.html

2. Batch change file name rename

With the man rename command you can tell that the rename command is actually a Perl script command,
It is dedicated to renaming multiple files in batches (rename multiple files).

command format:
Rename [-v] [-n] [-f] perlexpr [files]
Perlexpr is a regular expression in Perl script format.
Parameters:
-V,--verbose
Verbose:print Names of files successfully renamed.
Verbose mode: Print List of file names for successful changes
-N,--no-act
No action:show What files would has been renamed.
Test mode: Do not really execute commands, but just show which filenames should be done
Change, for test mode.
-F,--force
Force:overwrite existing files.
Mandatory mode: Overwrite already exists when changing file name if changed files already exist
The file.

Typical applications of rename:

0. Bulk Change file name extensions
$ ls
1.txt 2.txt 3.txt 4.txt
$ Rename ' s//.txt//.ext/' *
$ ls
1.ext 2.ext 3.ext 4.ext
1. Delete file name extensions in bulk
$ ls
1.txt 2.txt 3.txt 4.txt
$ Rename ' s//.txt//' *
$ ls
1 2 3 4
2. Batch Add File extension
$ ls
1 2 3 4
$ Rename ' s/$//.txt/' *
$ ls
1.txt 2.txt 3.txt 4.txt
3. Batch rename files on your own terms
$ ls
1.ext 2.ext 3.ext 4.ext
$ Rename ' s/(/d)/cap/' *
$ ls
1th Chapter EXT 2nd Chapter EXT 3rd Chapter EXT 4th Chapter Ext

3.

Method 1: Split the file name processing, you can arbitrarily modify the filename find-name ' *.log '-printf%f//n|awk-f '. ' ' {print $} ' |xargs-i{} mv {}.log Xiyun_{}.log Method 2: Use rename command under Rename General Linux to compare simple rename ' Test ' Xiyun ' *.log ' Replacing a part of a string in a file name with the Rename command in Ubuntu supports regular expressions and is therefore more powerful. Method 3: Use the Find and Xargs and MV directly, without awk in the middle, so you can add only the suffix name, cannot modify the file name.

From:http://blog.chinaunix.net/u/22583/showart_1964649.html

Batch file name modification under Linux (rename)

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.