The rename command in the Linux command is mainly used to rename files. It is similar to the mv command, but rename can rename batch files, while mv commands can only rename individual files. This section describes how to use the Linux rename command.
Linux's rename command has two versions, one version of the C language, is a version of the Perl language, the early Linux distributions basically using C language version, is now very It's hard to see the C language version. For historical reasons, when the Perl language is in full swing, Linux tool developers believe that Perl can replace C, so most of the tools that were originally C versions have been rewritten by Perl because The Perl version supports regular processing, so the function is more powerful, and the C language version is no longer needed.
How to distinguish which version of the rename command in the system?
Enter man rename to see the first line is
RENAME(1) Linux Programmer’s Manual RENAME(1)
Then this is the C language version.
And if it appears:
RENAME(1) Perl Programmers Reference Guide RENAME(1)
This is the Perl version!
Syntax differences between the two versions:
In C language, according to the annotation above man,
The syntax of rename is:
rename fromtofile< Br>
This command has three parameters, which are: from: change the name, to: change to what name, file which file needs to be modified.
Example usage:
For example, there are a number of files that start with log, log001.txt, log002.txt ……. Until log100.txt
Now I want to replace all the logs of this batch of files with history
rename log history log*
The meaning of this command is very clear, Replace the log characters in all files starting with log with history
. The replaced file is: history001.txt, history002.txt …. . Until history100.txt
rename Another C example of the C language version is to modify the suffix name in bulk,
For example, we want to change all jpeg suffix image files to jpg files.
rename .jpeg.jpg*.jpeg
Thus, all extensions with .jpeg extensions are all modified to .jpg
Now summarize the rename C language version. What you can do: Modify the file name in batches. The result is that each file will be replaced with the same string! That is to say, it is impossible to implement such as loop and then rename by number!
Batch renaming of Perl versions, with the benefit of Perl, is that you can use regular expressions to do very fancy features.
Param version of the parameter format:
rename perlexprfiles
Note that the perl version of rename has only two parameters, the first parameter is perl regular expression, the second The parameter is the file to be processed
Help example for man rename:
1) There is a batch of files ending with .bak, and now I want to remove all these .bak.
rename ‘s/\\.bak$//’ *.bak
This command is very simple, because I have not systematically studied perl, I don't know the replacement string in perl Is it doing this, but sed is doing this, so if you have a sed or tr basis, it is easy to understand that this substitution is exactly the same as the regular syntax in sed.
2) Change all file names containing small and small letters to lowercase letters.
rename & lsquo;y/A-Z/a-z/& rsquo; *
Still the same as sed's replacement grammar, no need to explain more, if you can't read it, you can learn sed first.
There are several more practical examples:
Batch removal of spaces in file names
Linux file names originally do not support spaces, I don't know when it is allowed. Of course, when calling the file on the command line, the space is very problematic. For example, you can directly mv oldfile newfile but there is a space, you can add double quotes: mv “oldfile” “newfile” Slash transfer \\[], this is fine, but if you directly introduce the name of the picture containing the space into the Latex document, Latex will directly print out the file name when generating the pdf. This problem has been a long time for me. How about the pdf I generated? What is the name of the file? Later I discovered that it was a problem with spaces in the file name! The file name generated under windows system is born with spaces. Although it is very annoying, some images generated by HP scanners add spaces by default. There is no way to remove them. Before the system research rename command, I removed it with mv. Spaced.
Previous12Next Total 2 Pages
In Linux system operation, tools can be used to monitor network traffic, but there
In Linux systems, if the program in tomcat is unstable, tomcat will report an excep
As a Linux system administrator, you need to manage the permissions of Linux users and groups, espec
Linux is a free-spreading operating system, Linux system processes can operate on any file, database
Linux how to debug multi-process program
What should I do if the device id of the Linux virtual machine does not match the drive letter?
Linux installation and deployment of LXC method details
Linux steps to send mail through the command line
How to use the fuser tool on Linux
How to install and upgrade VMware Tools in Fedora
Introduction to multi-threaded shell scripts in Linux system
Fedora 19 download and install NixNote steps
What shortcuts do Linux systems use with Visual Studio?
Ubuntu set the default method summary method
Linux system settings ssh connection interrupt time skills
What should I do if the Linux system SSH has experienced 1 errors?
The unknown automatic wallpaper change function
Quickly create a backup method for Win7 system
Win10 OneDrive can't sync file solution
How to install and configure DenyHosts tool
How to delete the RECYCLER folder on Windows 7 system?
Vista's five major storage features introduced
Win10 Redstone 11082 video gets started quickly: a list of known bugs and new changes
How to replace the default font of Windows7 system?