rename multiple files in linux

How to Rename Multiple Files in Linux

Sometimes you may need to change the names of multiple files & folders in Linux. Although Linux provides mv command to rename files, it does not support renaming multiple files & folders at once. In this article, we will look at the various tools available to rename multiple files in Linux.


How to Rename Multiple Files in Linux

Here are the different tools to rename multiple files in Linux.


Rename utility

Rename is a useful tool that allows you to easily rename multiple files. Here is the command to install it.

$ sudo apt install rename

Let us say you have the following files

ls
file1.txt file2.txt file3.txt

You can rename files using pattern matching as shown below. We will rename file with test in all our file names above.

$ sudo rename 's/file/test/' *
$ ls
test1.txt test2.txt test3.txt

Rename provides many useful options such as capitalization, force overwrite that you can figure out using man rename command.

Also read : How to Install & Configure Squid Proxy Server in Linux


Rename multiple files using mmv

mmv is another useful tool that allows you to easily rename multiple files & folders at one go. Here is the command to install it.

$ sudo apt-get install mmv

Let us say you have the following files

$ ls
file1.txt file2.txt file3.txt

Let us say you want to rename them test1.txt, test2.txt and test3.txt respectively. Here is the command to do it.

$ mmv file\* test\#1

In the above command, we specify to rename file with test in files & folders present in our current directory. We use * wildcard character in from pattern to indicate all files starting with filename file. We also use #1 in to pattern to match the first wildcard pattern in from part. So in this case #1 matches * and effectively means test\*

mmv comes with numerous options. For more details, you can run man mmv command.

In this article, we have seen couple of ways to rename multiple files in Linux.

Also read : How to Extract .bz2 File in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *