How do I change the file name with a command? Under Linux You can use the Rename command, and of course you can use the MV command to share the usage of the Linux Rename command.
Some people say that there is no rename command in Linux, we recommend that you use the MV command.
Make a comparison between the rename command and the MV command in renaming the file, and you should use it according to your preference.
MV Command, Introduction to MV command in man MV:
Mv-move (rename) files
You can see that the MV command does have the ability to rename, but in practice, it can only rename a single file, with the following command:
MV [Path/]oldfilename [Path/]newfilename
The "MV command can only rename a single file", which is the fundamental difference between the MV command and the Rename command in terms of renaming.
Rename command, description of the man rename:
NAME
Rename-rename files
Synopsis
Rename from to file ....
DESCRIPTION
Rename would rename the specified files by replacing the first occurrence of from in their name by to.
For example, given the files foo1, ..., foo9, Foo10, ..., foo278, the commands
Rename foo foo0 foo?
Rename foo foo0 foo??
Would turn them into foo001, ..., foo009, foo010, ..., foo278.
and
Rename. htm. html *.htm
Would fix the extension of your HTML files.
You can see that the Rename command is dedicated to file renaming, and according to the following example, rename can rename a batch file in addition to renaming a single file.
Note that the Rename command is a 2 parameter with 3 parameters and not many people think.
Related reading:
- Introduction to Linux Rename command usage
- Find command and rename bulk modify file name suffix
- Example tutorial for batch renaming of rename commands under Linux
- Change the file name extension under Linux (Find command \\rename command)
In the example above, the use of batch renaming of two files is given, in fact, the rename is used in conjunction with wildcards, which is more powerful than the example shown above.
The basic wildcard characters are as follows:
? can replace a single character
* Can replace multiple characters
[CharSet] can replace any single character in a charset set
Description
such as folders have these files Foo1, ..., foo9, Foo10, ..., foo278, if you use
Rename foo foo0 foo?
It will only rename the foo1 to foo9 file to Foo01 to foo09, because the wildcard can only replace a single character, so the renamed file is only a file with a 4-character-length name, and foo in the file name is replaced with Foo0.
Then continue to use
Rename foo foo0 foo??
All foo01 to foo99 files in the folder are renamed to Foo001 to foo099, and foo100 and later filenames are not changed, because the wildcard is used, so only files with a 5-character-length name are renamed, and Foo in the file name is replaced with Foo0.
If you continue to use
Rename Foo foo0 foo*
All files foo001 to foo278 are renamed to foo0001 to foo0278 because the wildcard * can replace multiple characters, so all files starting with Foo are renamed, and Foo in the file name is replaced with Foo0.
Then look at the use of the wildcard [CharSet], or continue in the folder described above, execute the following command
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.
In use, three wildcard characters can be used in conjunction with each other.
In short, both the Rename command, or the MV command can be done to modify the file name, when using more attention to the different parameters and usage.
Translated from: Rename command usage in Linux (rename file)
http://www.jbxue.com/LINUXjishu/24414.html slightly modified.