Batch renaming and replacing File Content

Source: Internet
Author: User
In text operations, you can often find, replace, and rename the entire file. in Linux, it is quite convenient. In Windows, you need to use special tools. The following are some simple methods in Linux, which are successfully debugged in ubuntu9.10.

1. RENAME command is used for batch renaming

Rename Syntax:

RENAME [-V] [-N] [-F] perlexpr [files]

-V indicates that the detailed information is displayed, and-N indicates that the replacement is not performed, but the files will be affected. -F
Indicates mandatory, regardless of whether there are duplicate names.

Perlexpr is a Perl syntax expression,
Files is a match. Therefore, the command execution result is related to perlexpr, not necessarily the file name.

Instance: change all file names *. html to corresponding .htm.

Rename's/\. html $/\. htm $/'*. html

Remove the Bak suffix

Rename's/\. Bak $ // '*. Bak

Change the file name to lowercase in uppercase.

Rename 'y/A-Z/a-z /'*

However, rename cannot be modified recursively.

2. recursively rename the name, using find + rename

Change the ABC file name to XYZ.

Find.-Name "ABC *"-exec rename's/ABC/XYZ /'{}\;

This command can be used to change the name of all subdirectories in the current directory.

3. Replace the content with find + SED

Replace all ABLO with ablozhou

Find.-Type F-exec sed-I-e "s/ABLO/ablozhou/g "{}\;

Sed command-I indicates -- in-place, and the file is replaced in the original place. -E followed by the replacement expression.

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.