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.