How to Rename Multiple Files in Linux

Channel: Linux
Abstract: $ rename.ul txt sql *.txt The preceding command will change the extension of all files from .txt to .sql. 3. Batch renaming files Using Vimv Vimv util

In a Linux system, you can easily rename a file using mv command. But, if you have multiple files which you want to rename, in this situation you need some extra tools or built-in Linux utilities for solving this problem.  

In this tutorial, we learn the different methods to rename multiple files in a Linux system at once.

1. Rename a Batch of Files using Rename Command

Using the rename command, you can easily rename a batch of files using a just single command. The following syntax is used for running the rename command:

Download Multiple Files (or ULRs) i...

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

Download Multiple Files (or ULRs) in Parallel with Python
$ rename options <perl_expression> <files>

For example, we want to rename the extensions of multiple from .sql to .html. The following rename command easily can do this action:

$ rename 's/\.sql$/\.html/' *.sql
Rename command options

The following options help you to optimize the rename command output:

When you use rename command along with the option ‘-n’, it displays which file is to be renamed as follows:

$ rename -n 's/\.html$/\.txt/' *.html

When you use the -v tag along with the rename command, it shows the file names that have been renamed.

$ rename -v 's/\.html$/\.sql/' *.html

You can also rename files from upper case letter to lower case using the rename command in the following way:

$  rename -v 'y/A-Z/a-z/' *.SQL

Similarly, you can also change the multiple file names from lower case to upper case using the rename command.

$  rename -v 'y/a-z/A-Z/' *.sql

To explore more options and working of rename command you can get help using the following command:

$ rename --help
2. Rename multiple files using rename utility

The rename utility ‘rename.ul’ which is part of util-Linux allows us to rename a batch of files. Ubuntu, Debian, and most of the other Linux distribution ships with this rename utility.

You must be careful while running the rename utility for renaming multiple files because this utility will rename all files that would be present in the current working directory.

The following text files are present in our home directory that we have listed using the ‘ls’ command.

For example, we want to only change the file names without changing all file extensions. In this case, the rename utility will help us in the following way:

$ rename.ul File Script *.txt

The preceding command will rename all files Files to the new name Script. Similarly, you can also change the file extension of all these files as follows:

$ rename.ul txt sql *.txt

The preceding command will change the extension of all files from .txt to .sql.

3. Batch renaming files Using Vimv

Vimv utility also provides the functionality to batch renaming files. You can get this utility on your system from Github using the following git clone command:

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

Now, using the cp command, 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

Navigate into the files directory that you want to rename through the terminal and run the vimv command.

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

4. Bulk rename files using qmv

Qmv (quick move) tool is included in the renameutils package. Using Qmv, you can rename multiple or bulk files in a very short time using your favorite text editor. First, install the renameutil packages by using the following command:

$ sudo apt install renameutils

Now, move into the files directory and run the following command:

$ qmv

After that, the following window shows inside the terminal:

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

5. Rename all files Using mmv

Using the mmv tool, you can rename multiple files using standard wildcards in a Linux system. First, install the mmv utility.

$ sudo apt install mmv

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

$ mmv \*.sql \#1.txt

In the preceding command, the ‘#1’ is used to specify the file pattern.

You can also change the file name using the mmv command. For example, we want to change the file name ‘file’ to ‘script’ with a similar file number pattern.

$ mmv '*file*' '#1script#2'
6. Bulk Rename Files Using Thunar file manager

Thunar is one of the most popular file managers of Linux systems. It also provides functionality to rename multiple or bulk files. This tool can be installed on Ubuntu and its derivatives by using the following command:

$ sudo apt get install thunar

To launch the interface of Thunar file manager, type the following command on the terminal:

$ thunar -B

The following new Thunar file manager window appears on the desktop. Using various available options, you can easily rename bulk files on your system.

7. Batch Rename Files using Emacs

Using the Emacs text editor, you can also rename multiple files together without installing any extra package or plugin on your system. Open the emacs text editor on your system and press 'Alt+X' to shift on the command mode. Now, using the following command enable the writable directory editor mode:

dired

Enter the directory path where all files are located which you want to rename. 

Now, press 'Ctrl+X' along with 'Ctrl+Q' to move into the read/write mode.

The following window will show on your screen:

Change the file names and then press 'Ctrl+C' to save changes. Type the ls command to verify changes.

Conclusion

We presented 7 different ways through which you can rename a bunch of files on your Linux system at once.

Thanks for reading, please leave your feedback and suggestions in the comment section.

Ref From: linoxide
Channels:

Related articles