Just learning Linux, renaming the file in the head immediately presented a rename command, but it was not used up. G A bit, is still smattering, and found that many people are also very unfamiliar with it! There are some children's shoes said that the direct use of MV, ah, MV is really useful, but the old feeling command name is so not pleasing to the eye!
Let's go man.
Mv-move (rename) files
The MV has not only the function of transfer, there is indeed the meaning of renaming, the syntax is simple can be understood as:
MV [Path/]oldfilename [Path/]newfilename
But it can only be the same name as a file.
we'll come again, man rename. :
Rename-renames Multiple Files
You can see that the Rename command is dedicated to file renaming, and it is renaming a batch file.
Rename version of Linux
There are two versions of the Linux Rename command, one in C and one in Perl, and the earlier Linux distributions are basically in the C language, and it's hard to see the C language version, because of historical reasons, in the Perl language rounds, Linux tool developers believe that Perl can replace C, so most of the tools are originally C version of Perl rewrite, because the Perl version of the support of the regular processing, so the function is more powerful, it is no longer required in the C language version.
How can I tell which version of the Rename command is in the system?
Enter man rename See the first line is
RENAME (1) Linux Programmer ' s Manual RENAME (1)
So this is the C language version. And if it appears that:
RENAME (1) Perl Programmers Reference Guide RENAME (1)
This is the Perl version!
Syntax differences for two versions
- In the
- C language, the syntax of rename is as follows:
rename fromtofile
D This command has three parameters, from: What name to change, to: What name to change, and which file to modify.
Usage example: For example, there are a batch of files that start with log, Log001.txt, log002.txt .... Until Log100.txt, now want to replace the log of this batch of files with the history
rename log History log*
The meaning of this command is clear, replace the log character in all files that begin with log with the history, so the replaced file is: History001.txt, History002.txt ..... Until the history100.txt.
- A Perl version of batch renaming, with the benefit of Perl, is that you can use regular expressions to accomplish very peculiar functions. The format of the parameters for the Perl version:
Rename perlexpr files
Example of a man rename: There are a batch of files that end with. Bak and now want to get rid of these. Bak:
Rename ' s/\.bak$//' *.bak
This command is simple because I haven't learned Perl yet, and I don't know if Perl replaces the string in this way, but SED does so, so if you have sed or TR basics, it's easy to see that this substitution is identical to the regular syntax in SED.
Summary: So if you just duplicate a file, then the MV is convenient and quick!
Linux Rename command rename and MV details