Renaming files in Linux is one of the easiest tasks that you can accomplish straight from the command line.
There are quite a few ways you can achieve this and in this guide, I will take you through how you can rename files in Linux.
Table of Contents
1) Rename files using mv Command
The mv command is one of the easiest commands you can use to rename files in Linux. The syntax is quite straightforward.
# mv old_file new_file
I have created a new folder in my home directory called files. In the folder, I have a document called file1.txt.
To rename the 'file1.txt' to 'file2.txt', the command will be
# mv file1.txt file2.txt
You can verify the results using the
To get verbose output, append the -v flag
# mv file1.txt file2.txt -v
'file1.txt' -> 'file2.txt'
If the file is located in a file path e.g. / home/winnie/file1.txt, the syntax will be
# mv /home/winnie/file1.txt /home/winnie/file2.txt
If you specify a different file path, the mv command will simply move it to a different location without renaming it.
2) Rename multiple files using the rename command
The rename command can also be used to rename multiple files from one format to another. The syntax is
# rename 's/old/new/' files
For example, I have 5 files- file1.txt, file2.txt, file3.txt, file4.txt, and file5.txt
To rename them all files (*.txt) to pdf (*.pdf) run
# rename 's/txt/pdf/' *.txt
The wildcard symbol means that all files will be affected.
To change filenames from lowercase to uppercase run
# rename 'y/a-z/A-Z/' *.png
In the above case, all lowercase png files will be converted to Uppercase
To view the man page of rename run
# man rename
3) Using Metamorphose2 GUI tool
For GUI lovers, Metamorphose is a handy and powerful tool for renaming operations. Metamorphose is a free and open source cross-platform file and folder renamer, available for both Linux and Windows.
First off, head out to Metamorphose website and select your distribution's installer. A couple of installer options are available e.g. Debian files for Ubuntu and Debian and RPM for RedHat based distros such as CentOS.
Once downloaded use the
dpkg command to install
# dpkg -i metamorphose_1.1 2-2_all.deb
After successful installation of Metamorphose2, launch it on a terminal, by running
Choose your preferred language and click 'Ok' button
Click on the renamer tab. A Window like the one below will be displayed. On the left pane is a list of actions that you can take when renaming. in the middle section, these actions are further explained in detail.
Next, click on 'Picker' tab and click on the folder containing the files you want to rename. Highlight the files.
Thereafter, click on the 'Renamer' tab again and this time define the renaming rules. In the example below, I'm replacing 'file' with 'doc'.
The bottom section gives you a preview of how your files will be renamed.
Once satisfied, click on the 'Go' button
3) Using Pyrenamer GUI tool
Pyrenamer is yet another handy tool you can use to rename a batch of files simultaneously in Linux. To install in Ubuntu run
# apt-get install pyrenamer
To launch Pyrenamer run
Once launched, scroll down to your directory and select the files you want to rename. Next, choose the actions you wish to apply. In my case, I will replace the extension txt with pdf.
To effect the changes, I will finally click on 'Rename'
In this article, we have touched on various ways you can rename files - both individual files and batches of files - on the terminal and using GUI tools. Give it a try and let us know how it went! Thanks and keep it locked for more informative tutorials!