Linux rename Command

Source: Internet
Author: User

Different from the rename Command in Dos, the rename Command in linux is very powerful.

# Man rename

NAME
Rename-Rename files

SYNOPSIS
Rename from
To
File...

DESCRIPTION
Rename will rename the specified files by replacing the first occurrence of from in their name by.

For example, given the files foo1,..., foo9, foo10,..., foo278, the commands

Rename foo foo0 foo?
Rename foo foo0 foo ??

Will turn them into foo001,..., foo009, foo010,..., foo278.

And
Rename. htm. html *. htm

Will fix the extension of your html files.

We can see from the above:

1. The rename Command has three parameters.

2. the rename Command supports batch renaming of wildcards

3. Will the rename command support regular expressions?

Rename Parameters


 

Rename Command Format:
Rename [-v] [-n] [-f] perlexpr [files]

First parameter: replaced string
Second parameter: string to be replaced
Third parameter: match the file mode to be replaced

Eg: rename main1.c main. c main1.c rename main1.c to main. c

Rename supports wildcard characters

? Can replace a single character
* Replace multiple characters
[Charset] can replace any single character in the charset set

Eg: The folder contains these files foo1,..., foo9, foo10,..., foo278,

If you use rename foo foo0 foo?

The names of foo1 to foo9 will be renamed to foo01 to foo09. The renamed file only contains four characters in length, and foo in the file name will be replaced with foo0.

If you use
Rename foo foo0 foo ??

All the files from foo01 to foo99 are renamed to foo001 to foo099. Only five characters of name are renamed, AND foo in the file name is replaced with foo0.

If you use
Rename foo foo0 foo *

All files from foo001 to foo278 are renamed to foo0001 to foo0278, and all files starting with foo are renamed.

If you use


Rename foo0 foo foo0 [2] *

All files from foo0200 to foo0278 are renamed to foo200 to foo278, and foo0 in the file name is replaced with foo.

Rename supports regular expressions






 

Eg:

Replace rename "s/AA/aa/" * // replace AA with aa in the file name
Modify the file suffix rename "s //. html //. php/" * // change the. html suffix to the. php suffix.
Batch Add the file suffix rename "s/$ //. txt/" * // end all file names with txt
Batch delete file names rename "s //. txt //" * // delete all file names ending with. txt

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.