The batch modification name __linux under Linux

Source: Internet
Author: User

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

For example, modify all the tables for cdb1_* to cdb_*.
In this table of contents
Just need # rename ' cdb1 ' CDB ' *

I used to write a for loop to do ... Think about how stupid 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 through 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 a Perl script format.
Parameters:
-V,--verbose
Verbose:print Names of files successfully renamed.
Verbose mode: Prints the list of file names that successfully changed
-N,--no-act
No action:show What files would have been renamed.
Test mode: Does not really execute the command, but only shows which file names should be done
Change, for test mode.
-F,--force
Force:overwrite existing files.
Coercion mode: When changing the filename, overwrite already exists if the changed file already exists
of the file.

Typical applications of rename:

0. Batch change file name extension
$ ls
1.txt 2.txt 3.txt 4.txt
$ Rename ' s/\.txt/\.ext/' *
$ ls
1.ext 2.ext 3.ext 4.ext
1. Bulk Delete file name extension
$ ls
1.txt 2.txt 3.txt 4.txt
$ Rename ' s/\.txt//' *
$ ls
1 2 3 4
2. Batch Add file name extension
$ ls
1 2 3 4
$ Rename ' s/$/\.txt/' *
$ ls
1.txt 2.txt 3.txt 4.txt
3. Batch rename files in their own way
$ ls
1.ext 2.ext 3.ext 4.ext
$ Rename ' s/(\d)/Chapter VII/' *
$ ls
1th. EXT Chapter 2nd. EXT 3rd Chapter. EXT 4th Chapter. Ext

3.

Method 1: The file name split processing, you can arbitrarily modify the filename find-name ' *.log '-printf%f\\n|awk-f '. ' ' {print} ' |xargs-i{} mv {}.log Xiyun_{}.log method # 2: It is simpler to use rename commands under rename General Linux Rename ' Test ' Xiyun ' *.log ' to put a part of the file name The string replaces the Rename command under Ubuntu to support regular expressions, so the functionality is more powerful. Method 3: Direct use of Find and Xargs and MV, in the middle without awk, so you can only add suffix name, can not modify the file name

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.