- 6 Methods To Rename Multiple Files At Once In Linux
- Introduction
- Rename multiple files at once in Linux
- Method 1 — Using mmv
- Method 2 — Using rename utility
- Method 3 — Using renameutils
- Install renameutils in Linux
- 1. qmv
- 2. qcp
- 3. imv
- 4. icp
- 5. deurlname
- Method 4 — Using vimv
- Method 5 — Using Emacs
- Method 6 — Using Thunar file manager
- How to Rename Multiple Files at Once on Linux
- Rename Multiple Files With mv
- Rename Multiple Files With rename
- Rename Multiple Files With mmv
- Bulk Rename Files via GUI
- Renaming Multiple Files on WSL
- Conclusion
- 2 thoughts on “How to Rename Multiple Files at Once on Linux”
6 Methods To Rename Multiple Files At Once In Linux
In this tutorial, we will learn how to rename multiple files at once in Linux using various tools. All examples provided here are tested in Ubuntu 18.04 LTS, however they should work on any Linux operating systems.
Introduction
As you may already know, we use mv command to bulk rename or move files and directories in Linux and Unix-like operating systems.
But, the mv command won’t support renaming multiple files at once. It can rename only one file at a time. What would you do if you wanted to rename multiple files at a time? Worry not!
There are a few other utilities available for batch renaming files in Linux.
Rename multiple files at once in Linux
There could be many commands and utilities to a rename bunch of files. As of writing this, I know the following methods only. I will keep updating the list if I come across any new method in future.
Method 1 — Using mmv
The mmv utility is used to move, copy, append and rename files in bulk using standard wildcards in Linux and Unix-like operating systems. It is available in the default repositories of Debian-based systems.
To install mmv on Debian, Ubuntu, Linux Mint, and Pop OS, run the following command:
Let us say, you have the following files in your current directory.
Now you want to rename all files that starts with letter «a» to «b» . Of course, you can do this manually in few seconds.
But just think if you have hundreds of files and want to rename them? It is quite time consuming process. Here is where mmv command comes in help.
To rename all files starting with letter «a» to «b» , simply run:
Let us check if the files have been renamed or not.
As you can see, all files starts with letter «a» (i.e a1.txt , a2.txt , a3.txt ) are renamed to b1.txt , b2.txt , b3.txt .
Explanation
In the above example, the first parameter ( a* ) is the ‘from’ pattern and the second parameter is ‘to’ pattern ( b#1 ).
As per the above example, mmv will look for any filenames staring with letter ‘a’ and rename the matched files according to second parameter i.e ‘to’ pattern.
We use wildcards, such as ‘*’ , ‘?’ and ‘[]‘ , to match one or more arbitrary characters. Please be mindful that you must escape the wildcard characters, otherwise they will be expanded by the shell and mmv won’t understand them.
The ‘#1′ in the ‘to’ pattern is a wildcard index. It matches the first wildcard found in the ‘from’ pattern. A ‘#2′ in the ‘to’ pattern would match the second wildcard and so on.
In our example, we have only one wildcard (the asterisk), so we write a #1 . And, the hash sign should be escaped as well. Also, you can enclose the patterns with quotes too.
You can even rename all files with a certain extension to a different extension. For example, to rename all .txt files to .doc file format in the current directory, simply run:
Here is an another example. Let us say you have the following files.
You want to replace the the first occurrence of abc with xyz in all files in the current directory. How would you do?
Please note that in the above example, I have enclosed the patterns in single quotes.
Let us check if «abc» is actually replaced with «xyz» or not.
See? The files abcd1.txt, abcd2.txt, and abcd3.txt have been renamed to xyzd1.txt, xyzd2.txt, and xyzd3.txt.
Another notable feature of mmv command is you can just print output instead of renaming the files using -n option like below.
This way you can simply verify what mmv command would actually do before renaming the files.
For more details, refer man pages.
Method 2 — Using rename utility
The rename utility will rename given files by substituting the first occurrence of expression in their name by replacement.
The rename command comes preinstalled in most Unix-like operating systems. If it is not available by default, run the following command to install it on Debian-based systems:
For instance, I have the following files in the current directory.
Let us replace the the first occurrence of abc with xyz wherever found. To do so, run:
Now, verify if the changes have been made with ls command.
Sometimes, you might to just print output instead of renaming the files. If so, use -n flag to display which renames would occur without performing them:
As you can see, the above command didn’t make any changes, instead just displays which renames would occur.
You can force renaming task even if the operation would overwrite existing files using -f flag like below.
If you don’t want to overwrite the files, you can simply convert them to upper or lowercase letters (and vice versa) to prevent «already exists» errors.
To convert all filenames to lower case, so:
Let us check if the changes have been made.
Yes, the letters in the filenames have been changed from lower case to upper case.
Similarly, to convert filenames to lower case, run:
We can remove all blank lines in a filename as well. For example, I have the following file.
To remove all blank spaces in the above filename, run:
Now, the filename doesn’t have any blank spaces.
Replace blank spaces with underscores:
You might want to change the file extension, but not rename the filenames. It is also possible. The following command would rename all *.txt files to *.doc .
Verify the changes using ls command:
To remove extension in all files matching .txt, run:
For more details, refer man pages.
Method 3 — Using renameutils
The renameutils is a set of programs that is designed to batch renaming files and directories faster and easier.
Renameutils consists of the following five programs:
- qmv (quick move),
- qcp (quick copy),
- imv (interactive move),
- icp (interactive copy),
- deurlname (delete URL).
Install renameutils in Linux
Renameutils is available in the default repositories of most Linux distributions. To install it on Arch-based systems, enable the community repository and run:
On Debian-based systems:
Now, let us see some examples.
1. qmv
The qmv program will open the filenames in a directory in your default text editor and allows you to edit them.
I have the following three files in a directory named ‘ostechnix’.
To rename the filenames in the ‘ostechnix’ directory, simply do:
Now, change the filenames as you wish. You will see the live preview as you edit the filenames.
Alternatively, you can cd into the directory and simply run ‘qmv’ .
Once you opened the files, you will see the two columns as shown in the following screenshot.
The left column side displays the source filenames and the right column displays the destination names (the output filenames that you will get after editing).
Now, rename all the output names on the right side as you wish.
After renaming filenames, save and quit the file.
Finally, you will see the following output:
Now, check if the changes have actually been made using ‘ls’ command:
See? All files are renamed. Not just files, the renameutils will also rename the directory names as well.
Here is a quick video demo of qmv program:
If you don’t want to edit the filenames in dual-column format, use the following command to display the destination file column only.
Where, ‘-f’ refers the format and ‘do’ refers destination-only .
Now, you will see only the destination column. That’s the column we make the changes.
Once done, save and close the file.
For more details, refer man pages.
2. qcp
The qcp program works like qmv, but copies files instead of renaming them. In this case, you will get two instances of same file. That means it will keep both original and duplicate files.
Rename the filenames listed on the right side. Save and quit the file. Finally, verify the changes made using ls command:
For more details, refer man pages.
3. imv
The imv program allows us to interactively rename the filenames. Obviously, it is not for bulk renaming. You could only rename the files one by one.
Edit the filename as you like and hit ENTER to rename it.
For more details, refer man pages.
4. icp
The icp program is same as imv , but it copies the files instead of moving them.
For more use cases and commands, please refer man pages.
I don’t know why the developers added these two utilities while we can do the same using mv and cp command.
5. deurlname
The deurlname program removes URL encoded characters (such as %20 representing space) from file names. Some programs, for examples w3m, tend to keep those characters encoded in saved files.
You can this tool for cleaning up the filenames you downloaded from the Internet.
Take a look the the following file.
There are some special characters and numbers in the filename. If you clean it up, just run:
Now, look how the file name is changed.
The filename is clean and readable.
Refer man pages for more details.
Also, refer the project’s website given at the end of this guide.
Method 4 — Using vimv
As the name says, Vimv is a command line utility to bulk rename files using Vim editor. You can, of course, change the editor by changing the value of $EDITOR environment variable.
To install Vimv, git clone the repository:
Copy the vimv binary to your $PATH , for example /usr/local/bin/ .
Finally, make it executable:
Now go to the directory and run the following command to edit the filenames.
You will see the filenames in Vi editor. Press i to switch to interactive mode and edit the filenames as the way you edit text in Vi editor. Once done, press ESC key and type :wq to save and exit.
The files inside the directory should be renamed now. Here is a short video demo.
For more details, refer the project’s GitHub repository given at the end of this guide.
Method 5 — Using Emacs
If you have a system with Emacs editor installed, you can do batch renaming easily by following these steps.
1. Open your Emacs editor.
2. Press Alt+x and type the following and hit ENTER to switch to wdired-mode (short for «writable directory editor mode»).
3. Enter the path to the directory (E.g. /home/sk/ostechnix ) which contains the files to rename and hit ENTER key.
4. Then, press Ctrl+x and Ctrl+q to switch to read-write mode.
5. Now, rename the files. Once done, press Ctrl+c and Ctrl+c (two times) to save the changes. To abort the changes, press Ctrl+c and Ctrl+k .
Watch the demo video:
See? It is very simple to rename multiple files at once.
Method 6 — Using Thunar file manager
The Thunar file manager has built-in bulk rename option by default.
Thunar is available in the default repositories of most Linux distributions.
To install it on Arch-based systems, run:
On Fedora, RHEL, CentOS, AlmaLinux, Rocky Linux:
On Debian, Ubuntu, Linux Mint:
Once installed, you can launch bulk rename utility from menu or from the application launcher. To launch it from Terminal, use the following command:
This is how bulk rename looks like.
Click the plus sign and choose the list of files you want to rename. Bulk rename can rename the name of the files, the suffix of the files or both the name and the suffix of the files.
Thunar currently supports the following Bulk Renamers:
- Insert Date or Time
- Insert or Overwrite
- Numbering
- Remove Characters
- Search & Replace
- Uppercase / Lowercase
When you select one of these criteria from the picklist, you will see a preview of your changes in the New Name column, as shown in the below screenshot.
Once you choose the criteria, click on Rename Files option to rename the files.
You can also open bulk renamer from within Thunar by selecting two or more files. After choosing the files, press F2 or right click and choose Rename .
Suggested read:
And, that’s all for now. Hope this was useful. Do you know any other method to add in this list? Please mention them in the comment section below. I will check and update this guide accordingly.
Источник
How to Rename Multiple Files at Once on Linux
Renaming multiple files on Linux sounds like a simple task, but it can get rather complex. It’s possible to bulk rename files with the mv command and a bit of Bash scripting, or use the mmv and rename utilities – which aren’t ordinarily installed by default. In this guide, we’ll show various examples for renaming multiple files at once from the Linux command line.
Rename Multiple Files With mv
The mv command is a default part of Linux and can be used to rename multiple files, but a little scripting is required to do the job. Some examples also rely on other default Linux utilities like ls , find , xargs , etc.
Example 1. Change all file names to lowercase.
Example 2. Change all file names to uppercase.
Example 3. Change all file extensions from .jpeg to .jpg .
Example 4. Remove the .bak file extension from all files.
Example 5. Add a .bak file extension to all files.
Example 6. Use xargs to append “_backup” to every file.
Example 7. Use the find , sed , and mv commands to change all files to lowercase.
Example 8. Use the find -exec and mv commands to append “_backup” to every file ending in .log extension.
Example 9. Similar to the previous example, but replace find’s -exec option with xargs to append “_backup” to every file ending in .log extension.
Example 10. Replace a pattern in every file using mv and sed . This will replace “IMG” with “Vacation” in every .jpg file.
Example 11. Add the current timestamp to all files ending in .log . This would change a file such as access.log to access_20210418040151.log .
Rename Multiple Files With rename
The rename utility makes our bulk renaming tasks a bit easier, but the utility isn’t always installed by default. Use the appropriate command below to install it with your system’s package manager.
Ubuntu, Debian, and Linux Mint:
Fedora, AlmaLinux, CentOS, and RHEL:
Arch Linux and Manjaro:
Example 1. Change all file names to lowercase.
Example 2. Change all file names to uppercase.
Example 3. Strip the .bak extension from all files.
Example 4. Change the extension of all .jpeg files to .jpg .
Example 5. Change the uppercase extension .JPG to lowercase .jpg for all files.
Example 6. Remove blank spaces from all file names.
Example 7. Replace blank spaces with underscores for all file names.
Example 8. Capitalize the first letter of all file names.
Example 9. Replace a pattern in every file name. This command will replace “IMG” with “Vacation” in every .jpg file.
Example 10. Delete part of a file name. This command will remove “IMG_” from every .jpg file.
Example 11. Append the .bak extension to all files.
Rename Multiple Files With mmv
The mmv utility excels at renaming files based on patterns, such as removing or adding strings to all files, or rearranging parts of file names. It’s not usually installed by default, but you can use the appropriate command below to install mmv with your system’s package manager.
Ubuntu, Debian, and Linux Mint:
Fedora, AlmaLinux, CentOS, and RHEL:
Arch Linux and Manjaro (install from AUR):
Example 1. Change the extension of all .jpeg files to .jpg .
Example 2. Change all file names to lowercase.
Example 3. Change all file names to uppercase.
Example 4. Rearrange parts of a file name. This command will change music files with pattern Song-Artist.mp3 to Artist-Song.mp3 .
Example 5. Replace the first occurrence of “IMG” with “Vacation” in all file names.
Example 6. Add a prefix to every file name. This command will prepend “backup_” to every .log file.
Example 7. Add a suffix to every file name. This command will append “_backup” to every .log file.
Example 8. Remove the “IMG_” prefix from all .jpg files.
Example 9. Remove the “_old” suffix from all files.
Bulk Rename Files via GUI
If the command line isn’t really your thing, it’s possible to rename multiple files at once via GUI. One of the best tools to do the job is the Bulk Rename application that comes with Thunar.
Thunar is the default file browser for Xfce, but you can install it regardless of what desktop environment you’re using. If you’re already using Xfce or Thunar, then Bulk Rename is already part of your system. Otherwise, use the appropriate command below to install it with your system’s package manager.
Ubuntu, Debian, and Linux Mint:
Fedora, AlmaLinux, CentOS, and RHEL:
Arch Linux and Manjaro:
Step 1. After Thunar is installed, search for and open the Bulk Rename utility.
Step 2. Click on the plus sign to add files that you’d like to rename.
Step 3. Choose from the list of options what you’d like to do with the files. You can change them all to uppercase or lowercase letters, add a date and time, insert text at a certain position, add automatic numbering, replace characters, or search and replace certain patterns in the file names, among other things. In the example below, we’ve appended a .txt file extension to all of our files.
Step 4. When you’re happy with the previewed name changes in the “New Name” column, click on “Rename Files” to perform the bulk renaming.
Renaming Multiple Files on WSL
If you’re using Windows Subsystem for Linux, some commands above won’t work, particularly those that involve changing files to lowercase or uppercase. Windows is case-insensitive, thus considers File.txt , file.txt , and FILE.txt to all be the same file.
You’ll simply get an error that the file already exists if you try to rename FILE.txt to file.txt . To avoid this issue, use one of the following examples.
Example 1. Change the uppercase extension .JPG to lowercase .jpg for all files (using default utilities).
Example 2. Change the uppercase extension .JPG to lowercase .jpg for all files (using rename utility).
Example 3. Change the uppercase extension .JPG to lowercase .jpg for all files (using mmv utility).
Example 4. Change all file names to lowercase (using default utilities).
Example 5. Change all file names to lowercase (using mmv utility).
Conclusion
It’s possible to use default Bash utilities for all of your bulk renaming on Linux, but the rename and mmv tools make it a lot easier. We can also use Thunar’s Bulk Rename application when we prefer to use GUI over the command line. The examples in this guide cover a wide range of renaming scenarios and can be easily adapted to fit other needs.
If our content helped you, please consider buying us a coffee. We appreciate your support!
2 thoughts on “How to Rename Multiple Files at Once on Linux”
Thunar Bulk rename is worth mentioning as a GUI tool to do the job.
Thanks for the suggestion. We’ve incorporated it into the article.
Источник