Let’s assure you that renaming files in Linux isn’t as hard as it may seem for the first time. Writing a few simple commands can easily change the name of your files, especially if you’re doing it on a small number of files. You won’t need any special tools for it.
However, if you want to rename the entire batch of files in a folder, then running commands for every single file can be tiring. In that case, you can use a few tricks or apps that will help you save some time.
You can rename files in Linux in two ways:
By using the command-line interface:
By using GUI tools or a standalone application:
Let’s have a look then.
Renaming Files Using the ‘mv’ Command
The most basic and simple way to rename files in Linux is by using the ‘mv’ command. The syntax is as follows:
mv [option] file-name1.ext file-name2.ext
Here, ‘mv’ is shortened for ‘move.’ And the renaming of files or folders implies moving it from one name to another.
Also, ‘file-name1.ext’ is where you type the original, old name and ‘file-name2.ext’ is the new name you want to change to.
But this only works if the file is located in the current directory you’re in. If not, then you’ll need to specify the full path. Let’s show you how.
sudo mv /home/user/Files/file-name1.ext/home/user/Files/file-name2.ext
‘sudo’ or ‘su’ is used to obtain permission to rename files if they belong to the system files and folders.
Sometimes, there are chances that you might rename the file to an already existing filename. In such cases, you can use the ‘–i,’ read as interactive, to provide an extra layer of protection. It’ll ask you if you want to overwrite the file.
And if you want to list all the changes made by mv, you can use the ‘–v’ (verbose) option to do so.
Changing the Batch File Names Using the ‘rename’ Command
We’ll be honest here. This procedure requires a certain level of advanced knowledge. If you’re familiar with the regular expression, you’d already know. In case you don’t, we can still help you with plain batch renaming. You just need to follow this simple procedure given below.
Here’s the ‘rename’ syntax:
rename [option] 's/old/new/' file1.ext file24.ext
A few things to keep in mind here:
- You can’t skip the single quote before the ‘s’ symbol
- ‘s’ implies ‘substitute’
There are various available ‘options’ to choose from. For easy understanding, here they are:
- -v, verbose – This is used when you want to print the names of all the files successfully renamed.
- -n, no action – This is a test mode which prints the name of the file that needs to be renamed but isn’t renamed.
- -f, force – It allows existing files to be overwritten.
And options are always placed before the file name and after the ‘mv’ command.
Well, the ‘rename’ command can be really handy. How?
You can use it for various purposes. For instance, you can rename multiple files of the same type, and it works on file extensions as well.
To give you an example,
rename 's/.jpeg/.jpg/' *
The symbol (*) means that it’ll affect all files in the folder.
You can also use it to perform case-insensitive substitution using the ‘i’ modifier and ‘g’ to affect all occurrences of the expression. They are written at the end of the expression, just before the closing single quote:
rename -n 's/ARW/photo/gi' *.jpg
Let’s simplify this command. The (*) symbol implies that all the .jpg files that contain ‘ARW’ will change to ‘photo.’ However, the command wouldn’t actually rename the files. It’ll just print the names in the console window because of the ‘-n’ option.
And using the ‘y’ modifier, you can also change the file’s name from lowercase to uppercase. It can change the filenames on a complex level.
rename 'y/a-z/A-Z/' *.jpeg
It would translate the names of all .jpeg files from lowercase to uppercase.
The good thing about the rename command is that it doesn’t put your files at risk as the ‘-n’ option gives a useful preview of what the renamed file will look like.
Linux has a powerful command tool. But if you’re not comfortable with using the command line, you can always opt for GUI tools or a standalone application.
The first one on the list is:
There are chances you may not have heard of this application before. But if you’ve been in need of a Linux application for renaming multiple files, Metamorphose is at your disposal. It is an advanced cross-platform batch file used to rename files in Linux. It is available for both Windows and Linux.
How to Use
- Go to its website and download the file.
- After installation, run the app. The first tab you’ll notice is ‘Picker.’ Click on it and select the directory that contains the file you want to batch rename. One important thing to note here is that it can only support one folder per renaming action.
- After selecting, click on the ‘Renamer’ tab. On the left panel, you’ll find a variety of options to rename your files. ‘Insert’ option will let you insert terms to the name, while ‘length’ is about trimming the file name to a certain number of characters. There are also ‘move text,’ ‘replace,’ and ‘modify’ options.
- You’ll see a ‘Go’ button at the bottom pane. Once you’re done choosing the renamer action, click on the ‘go’ tab to run it. Luckily, there is also an ‘Undo’ option in case you want to revert all your changes.
pyRenamer – Renaming Made Easy
As the name suggests, pyRenamer is written in Python.
It doesn’t matter whether you’re a beginner or an advanced user, everything can be done in just a few simple clicks using the pyRenamer application. From replacing any string of texts with another to changing file names to uppercase, sentence case or lowercase, removing accents and duplicate symbols from filenames, and adding or removing spaces and underscores, you can do it all at the tip of your mouse click.
And the procedure is pretty simple. The interface consists of four parts:
- A left panel where you can browse and select files and folders
- A central preview pane that shows the filenames before and after renaming
- A tabbed control area at the bottom of the page that lets you choose the renaming criteria
- And lastly, the options sidebar in the right corner
To rename the file, you need to select it in the tab area, choose your renaming option and preview it in the main area. Once done, confirm it by clicking on the ‘rename’ option.
If they wish to experiment with patterns, they provide a cheat sheet to make it easier. And an advanced user can rename graphics files and music by reading from their metadata.
Moreover, you can also manually rename just a single file instead of the whole bunch. You can install the application from their official website.
No doubt, pyRenamer is one powerful desktop application which can be used to rename files in Linux. It wraps the functionality of the mv and the rename commands into a user-friendly GUI.
Apart from these two, there are many similar GUI tools that can cover most of your bulk renaming needs.
Tell us in the comment section below how you rename files in Linux. We’d love to hear from you.