Best Ways to Batch Rename Files in Linux
Batch renaming files can be a daunting task, especially when you have hundreds or thousands of files to rename. In Linux, there are several ways to batch rename files, ranging from simple command-line tools to more complex graphical applications. In this article, we’ll explore some of the best ways to batch rename files in Linux.
- Using the mv command
The mv command is a powerful Linux tool that can be used for more than just moving files. You can also use it to rename files and directories. To rename a file with the mv command, open a terminal and type the following command:
“`
mv old_filename new_filename
“`
Replace `old_filename` with the current name of the file and `new_filename` with the new name that you want to assign to the file. For example, if you have a bunch of files with the name `file1.txt`, `file2.txt`, `file3.txt`, and so on, and you want to rename them to `newfile1.txt`, `newfile2.txt`, `newfile3.txt`, and so on, you can use a command like this:
“`
mv file*.txt newfile*.txt
“`
This will rename all files that match the pattern `file*.txt` to the pattern `newfile*.txt`.
- Using the rename command
The rename command is another powerful tool that you can use to batch rename files. This command can be used to rename files based on patterns or regular expressions. To use the rename command, open a terminal and type the following command:
“`
rename ‘s/old_pattern/new_pattern/’ files
“`
Replace `old_pattern` with the current pattern of the file names that you want to rename and `new_pattern` with the new pattern that you want to use. For example, if you have a bunch of files with names like `file12.txt`, `file13.txt`, `file14.txt`, and so on, and you want to rename them to `newfile2.txt`, `newfile3.txt`, `newfile4.txt`, and so on, you can use a command like this:
“`
rename ‘s/file(\d+)/newfile$1/’ file*.txt
“`
This will rename all files that match the pattern `file*.txt` to the pattern `newfile*.txt`.
- Using Thunar Bulk Renamer
If you prefer a graphical interface, you can use Thunar Bulk Renamer, a powerful tool that comes with the Thunar file manager. To use Thunar Bulk Renamer, open the file manager, select the files you want to rename, and click on the “Bulk Rename…” option from the context menu. In the Bulk Renamer window, you can select from a wide range of renaming options, such as adding a prefix or suffix, changing the case, or using regular expressions.
- Using GPRename
GPRename is another powerful graphical tool that you can use to batch rename files. This tool provides a wide range of options, such as replacing text, inserting text, changing the case, or using regular expressions. To use GPRename, simply select the files you want to rename, right-click on them, and select the “GPRename” option from the context menu. In the GPRename window, you can select the renaming options that you want to use and preview the changes before applying them.