All the Ways to Rename Multiple Files in Linux

Written by: Subhash Chandra   |   Last updated: November 4, 2022

Linux users may have to rename file frequently and it is very easy to rename a single file. You can just use the mv command to rename one file. There might also be situations where a user or a Linux system administrator may have to rename multiple files at once. This is a completely different case and Linux supports multiple tools and commands to rename multiple files in one go.

In this tutorial, we learn different utilities to rename multiple files in Linux with examples.

Using the Rename Command

Use the rename command to easily rename multiple files or directories. The rename command provides various advanced options that can help you save time while renaming files based on a pattern match.

Installation

The rename command is not preinstalled on several Linux distributions. If the rename command is missing from your Linux computer, then you can manually install it. For example, to install the command on your Ubuntu system, type:

sudo apt install rename

Syntax

The basic syntax of the rename command is as follows:

rename options <perl_expression> <files>

For example, you can rename the extensions of multiple from .html to .xml using the following rename command:

rename ‘s/\.html$/\.xml/’ *.html
rename command linux example

More Examples

Rename command supports multiple options that can help you perform different operations. These examples will show you how to use these options:

The most common usage of the rename command is to change the file extension from .html to .sql:

rename ‘s/\.html$/\.sql/’ *.html

Use the -v option to display rename operation output on the screen:

rename -v 's/\.sql$/\.html/' *.sql
rename command linux example 2

To change a part of the file name, use the following rename command:

rename -v 's/record/example/' *.html
rename command linux example 3

To change the file names from lowercase to uppercase, use the following rename command:

rename -v 'y/a-z/A-Z/' *.html
rename command linux example 4

To rename multiple files that matches a particular pattern, for example the files that contains s or ex:

rename -v 's/(ex|s)ample/record/' *.html
rename command linux example 4

To rename all files with file extension .mp3 in the current directory, type:

rename -n 's/\[.*?\]|_//gs' ./*.mp3

The -n option does a trial run and to actually rename files use without it.

Using the Rename Utility

Use the rename utility, known as rename.ul, which is part of util-Linux that enable you to rename multiple files. The rename utility is preinstalled in Ubuntu, Debian, and several other modern Linux distributions. This utility renames multiple files that are present in the current working directory.

We have the following html files in the current working directory:

To rename multiple files without changing the file extensions, use the following rename utility command:

rename.ul record script *.html

This command will rename multiple files in the current directory from record to script. Similarly, you can also change the file extension of all these files as follows:

rename.ul html xml *.html

This command will change extension of all the files in the current directory from .html to .xml.

Using Vimv

You can use the Vimv utility to rename Linux files in a batch. To get this utility on your system from Github, use the following git clone command:

git clone https://github.com/thameera/vimv.git

 After you clone the Vimv Git repository on your system, use the cp command to copy the binary file to your $PATH variable and change permissions on this file to make it executable.

sudo cp vimv/vimv /usr/local/bin/
sudo chmod +x /usr/local/bin/vimv

Go to the directory where your files are stored, which you want to rename using the terminal, and run the vimv command.

using vimv to batch rename files

Press ‘i’ to move into the insert mode and bulk rename files. After renaming files, save and quit the vim editor.

Using qmv

Qmv, also known as quick move, utility is part of the renameutils package. Using Qmv, you can bulk rename files in a very short time using a text editor of your choice.

First, install the qmv using the following command:

sudo apt install renameutils

Go to the directory where your files are stored, which you want to rename using the terminal, and run the qmv command.

qmv

When you run the qmv command, the following window displays inside the terminal:

using qmv rename multiple files

You can edit the names of the files in the second column and save changes. After renaming files using the qmv, the following output shows on the terminal:

Using mmv

Use the mmv utility to bulk rename files based on wildcard patterns.

The mmv utility is not preinstalled on most Linux distributions, so you must first install it using the default package manager on your operating system.

Run the following command on Ubuntu to install mmw:

sudo apt install mmv

Use the mmv utility to change the extension of all the files in the current directory. The following example changes the extension of all the files from

For example, we want to change the extension of all files from .sql to .txt using mmv command.

mmv \*.html \#1.sql

To change all the file names from lowercase to uppercase:

To change the file names back to lowercase, type:

You can also change the file name using the mmv command. For example, you can change the file name ‘example’ to ‘record’ with a similar file number pattern:

mmv ‘*example*’ ‘#1record#2’

Using Thunar File manager

If you do not like working on a command-line interface, then you can use a graphical user interface (GUI) tool to rename multiple files in one go. One such GUI tool is Thunar file manager.

Thunar is one of the most popular file managers of Linux systems. It also provides functionality to rename multiple files. Thunar is not preinstalled on most Linux distributions, and you need to install it manually.

To install Thunar file manager on Ubuntu Linux, try the following command:

sudo apt install thunar

1. Launch the bulk file rename interface of the Thunar file manager:

thunar -B
using thunar bulk renaming

2. Click the Plus sign to add files that you want to rename.

3. Select the options to bulk rename files. You can change the file name case, date and time, insert text, automatic numbering, or even replace characters.

4. After you finalize the new names, listed in the New Name column, click Rename Files to confirm the rename operation.

Using Emacs

Using the Emacs text editor, you can also rename multiple files together without installing any extra package or plugin on your system.

1. Open the emacs text editor on your system: emacs

2. Press 'Alt+X' to shift on the command mode.

3. Enable the writable directory editor mode: dired

4. Enter the directory path where all files are located which you want to rename: /home/linuxopsys/Documents

5. Press 'Ctrl+X' along with 'Ctrl+Q' to move into the read/write mode.

emacs dired rename multiple files

6. Change the file names and then press 'Ctrl+C' to save changes.

7. Type the ls command to verify changes.

Using Bash

The bash scripts can automate rename operation, same as any other operation that bash files can do. Create a script file as shown in the following example:

sudo vi file_rename.sh

Add the following code to the script file that you created:

#!/bin/bash

for f in *.sql; do
 mv -- "$f" "${f%.sql}.pdf"
done

Execute the script that will change all file extensions from .sql to .pdf:

sh file_rename.sh

Conclusion

Renaming multiple files in one go is not an easy operation and you must know more than one options that you can use. If you are comfortable with bash scripts, then you can use bash to automate rename operations. The Thunar bulk rename operation is also useful for users that are not comfortable using the command-line rename tools.

About The Author

Subhash Chandra

Subhash Chandra

Subhash Chandra, an Oracle Certified Database Administrator and professional writer, works as a Consulting User Assistance Developer at Oracle, bringing over 15 years of experience to the role. He enjoys sharing his technological passion through how-to articles, simplifying complex concepts in Linux, Windows, Mac OS, and various other platforms and technologies for a wide audience.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment