Batch Rename Files in Linux(批量重命名linux)

Linux is a powerful open source system, it has a variety of commands and tools, it can help us to make complex tasks easier. For example, with the help of linux commands or tools, we can batch rename files, here we will introduce the three ways that can help us quickly batch rename files in Linux.

Generally, there are three kinds of methods to batch rename files in the Linux system.

First, the renaming command ”rename” is provided in the Perl language, based on the source code of more than 10 years ago, it was renamed from “qmv”, which is very easy to use:

sudo apt-get install rename

rename 's/.html/.txt/' *.html

This command can be used to rename files with the suffix of “.html” to “.txt”.

The second method is to use the command ”mmv” to batch rename files, which is provided in the mmv package, firstly, we should install the mmv package:

sudo apt-get mmv

Then run the command like this

mmv '*.html' '#1.txt'

The command will be used to rename the files with the suffix of “.html” to “.txt”.

The third way is to use the Perl script to batch rename files. We need to create a Perl script, for example, we can named as “batch.pl”:

#!bin/perl
@files = ;
foreach $file (@files) {
$file =~ s/\.html/.txt/;
rename($_,$file);
}

If we have created the Perl script, then we need to run the command like this :

perl batch.pl

The command will rename all the files with the suffix of “.html” to “.txt”.

In conclusion, by using the ”rename” command, “mmv” command, or Perl script, we can quickly and easily batch rename files in Linux, and the methods mentioned above all can achieve the same effect.


数据运维技术 » Batch Rename Files in Linux(批量重命名linux)