preface
In Linux, you can use the mv command to modify filenames, but it can only operate on a single file. If you want to execute in batches, you have to write the shell script, which is executed iteratively with for statements. However, another command in Linux supports batch substitution of filenames, which is rename, and rename supports regular expression matching.
It is important to note that the rename command has different syntax formats in different Linux distributions.
grammar
The syntax used in Debian or Ubuntu is:
rename 's/stringx/stringy/' files
Under CentOS or RedHat:
rename stringx stringy files
The parameters of rename are divided into three parts:
stringx: Replaced string stringy: Replace string files: List of matching files
For example,
For example, if I have the following file and I want to remove the @ symbol from all the files,
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
CentOS writes:
rename \@2x.png 2x.png *.png
Ubuntu writes:
rename 's/\@2x/2x/' *.png
conclusion