How to Rename Multiple Files in Linux


To this day, Linux systems are generally associated with power users, those tech-savvy people who are employed as software engineers, system admins, or in any other role in the IT industry, The truth is these operating systems have been around for a while now and they come loaded with features from every walk of life. It’s just that Microsoft Windows has had a head-start and people just know more about it. I believe, if people know about the ease of use of Linux systems and the plethora of options you get with them, they will become more popular with regular PC users.

In line with that, we will discuss how can you rename multiple files at once in Linux. I will demonstrate multiple ways how you can do so, using Ubuntu 22.04, but these commands also work on other Linux distributions. Let’s get started.

Why not use the “mv” command?

You might be wondering, why don’t we just use the “mv” command? The mv command can only help you rename one file at a time, not batches.

You might already know this, the mv command can help you rename single files at a time in nix-based systems, but you can’t use it in one batch. So, you need to look at other utilities and commands to do so. I’ll walk you through the commonly known methods.

Method 1 – Using the “mmv” utility

You can easily use the “mmv” utility to rename, move, copy and append multiple files through the use of standard wildcards in Linux. It’s not installed in Ubuntu by default but worry not, as you can easily install it through the default repository.

To install “mmv” on your Deb-based system, run:

$sudo apt-get install mmv


Rename-Multiple-Files-Linux

Using “mmv”

After the “mmv” utility installation completes, you are ready to batch-rename files. For this example, let’s say that we have 3 files in your Documents directory.

x1.txt, x2.txt and x3.txt


Rename-Multiple-Files-Linux

Now, let’s say that you want to change the name of all these and replace “x” with “y”. Though you can manually rename these files in a couple of seconds, imagine that you have to rename hundreds of files, that’s when “mmv” comes in handy. So, let’s rename the files using:

$mmv x\* y\#1


Rename-Multiple-Files-Linux

Now if we run the “ls” command or open up the file manager, you’ll see that the files have been renamed.

This scenario just details one example use of the utility; you can use it to learn more:

$mmv -help


Rename-Multiple-Files-Linux

Method 2 – Using the “rename” utility

The rename utility takes things a step further and allows users to rename any given file, by replacing the first occurrence of the specified expression in the filename.

Though the utility comes preinstalled with many distros, if yours doesn’t have it, you can install it using:

$sudo apt install rename


Rename-Multiple-Files-Linux

When the “rename” utility completes the installation, you can start renaming batches of files.

Using “rename”

To demonstrate what I meant in the previous paragraph, let’s have a couple of files with a string of characters in the name. Let’s say we have:

asdfg1.txt, asdfg2.txt, asdfg3.txt and asdfg4.txt

Rename-Multiple-Files-Linux



Out of the whole string, let’s replace only “sdf” with “xyz”. To achieve this, we need to run the rename command with the following inputs.

$rename ‘s/sdf/xyz’ *

Rename-Multiple-Files-Linux



In this command, we are telling the rename command to look for the string “sdf” and replace it with “xyz”. After this, you can run “ls” to see if the changes have taken place.

You can learn more about the rename utility by running:

$rename -help


Rename-Multiple-Files-Linux

Method 3 – Using the “renameutils” terminal utility

The “renameutils” is a set of tools designed specifically for renaming batches of files and directories effectively and efficiently. You can install these tools on Ubuntu 22.04 using:

$sudo apt install renameutils

Once this package is completely installed, you will get access to 5 tools:

1- Quick move (qmv)

2- Quick copy (qcp)

3- Interactive move (imv) (this doesn’t help with renaming multiple files at once)

4- Interactive copy (icp) (this doesn’t help with renaming multiple files at once)

5- Delete URL (deurlname) (this tool helps rename the file and remove URL encoded characters but doesn’t help with batch renaming)

Each of these tools comes in handy for unique scenarios. If you want to know more about any of these tools you can visit the man pages for any of these utilities. Let’s explore.

Using “qmv”

The quick move program opens up the names of all of the files in the directory using your default text editor and you can update them as you want. To demo this, you need to navigate to the directory containing your sample files, within your terminal.

You can load up the file names using:

$qmv

When it opens up the names in the editor, you will see two columns of names.

In the left column, you will get the original names of the files and in the right column, you get the destination names (the names you want to update).

Now, all you need to do is update the names in the column on the right, save the file and exit. After this, you will see that the names have been updated to what you selected.

Using “qcp”

The quick copy utility works by creating a copy of the file with the new name, rather than just renaming the original. You will see two copies of the same file, i.e., the old file and a copy with the new name.

So, let’s see how that works.

Navigate to your directory containing the files to be renamed and load it into your terminal using:

$qcp

You’ll see the names listed in a similar two-column format. Update the file names in the right column, save the file, and exit, and you will see the copies created in the same directory.

Conclusion

These are some of the most commonly used methods that you can use to rename huge amounts of files at once. A lot of other tools and utilities are also available that can easily help achieve these tasks.

If you’ve run into any issues at any step of the guide, feel free to engage us through the comments section below. I will help you resolve the issues without much hassle.

Print Friendly, PDF & Email
Categories