Renaming a file is one of the easiest things to do on the computer. It is the case of Windows, but in Linux OS, you need to write a bunch of codes to rename a file, directory or folder. Renaming files in Linux is not that much of a problem only if you know the necessary commands. In Linux, you can rename a file by using the commands or by using a standalone application. If you are new to Linux OS and want to figure out how to rename a file in Linux, follow the below steps.
Contents
Ways to Rename Files in Linux
- Using the File Manager in Linux
- Using pyRenamer application
- Using mv command
- Using rename command
Method 1: Rename a File in Linux using File Manager
File Manager is the in-built app used to manage all the files that are stored on your PC. Renaming the files, directory or folder in this method is quite similar to Windows PC.
Step 1: Open the File Manager and navigate to the file that you want to rename.
Step 2: Right-click on the file & choose Rename or left-click on the file & click F2.
Step 3: Enter the new name. The interface may differ. Dolphin and Caja will let you write over the old name while Thunar and Nautilus will open a small window to enter the new name.
By using the File Manager, you can rename the file or folder within three steps.
Method 2: Rename a File in Linux using pyRenamer application
pyRenamer is the best application to rename files in Linux. For a beginner, it the best way to rename files. If you want to install the pyRenamer app, visit the link http://bit.ly/2MzpKm5 and download the app on your Linux PC.
The pyRenamer app has four interfaces
- A branch view type for selecting the files and directories on the left side(similar to Windows PC)
- On the centre, a preview pane showing original filename and renamed filename
- On the bottom side, a tab for entering the old and new name
- On the right side, there is an Option bar
pyRenamer has a lot of renaming options like Patterns, Substitutions (Find and Replace in Windows), Insert / Delete, Manual Rename, Images, and Music. If you have any doubts, just place the cursor on the option, it will show you a small description of the option.
Step 1: Choose any of the files that you want to rename, using the branch view interface.
Step 2: After choosing the file, enter the new name on the New file name on the Manual rename tab.
Step 3: Click Preview to look at the changes that you have made.
Step 4: Look at the new names on the preview pane. If you want to do some changes, make those changes. If you are OK with that, click the Rename button.
Now all your selected files will be renamed. If you are new to Linux, stick to the pyRenamer app. If you want to explore some other renaming apps, KRename, Metamorphose2 are the standalone applications that you can try.
These are two methods that don’t involve CLI (Command Line Interface). If you don’t want to get into the coding process, stick with these two methods. Instead, you want to learn the coding procedure, follow the other two methods.
Method 3: Rename a File in Linux using mv command
The command mv is used to move files & folders and also used to rename files. Using commands in Linux is similar to working on the Command Prompt in Windows PC. The mv command is the simplest of all to rename the files in Linux.
mv oldname newname
The above is the syntax of the mv command. This syntax is used to rename directories and folders. If you want to rename the file which is not in the active folder, you need to type the full path or else you can go to the folder that contains the file.
Method 4: Rename files in Linux using the Rename Command
The rename command is techier than mv command as this command needs some knowledge about regular expression in Linux. But it’s not impossible. Using mv command you can rename only a single file. To rename multiple files, you need to use the rename command.
rename ‘s/oldname/newname/’
The above line is the syntax of the rename command. s for substitute and the single quotes are customary.
Other than s, there are many options available in Linux
- -n: No Action. A preview mode that will show you the changes without affecting the original file
- -v: Verbose. It will print the list of changed files with the recent changes
- -f: Forced. A forced overwrite to the original files
- -y: Complex Changes: Used to change the cases of letters.
Using the rename command, you can change the format of the file or multiple files. For instance,
rename ‘s/.tiff/.png/’
The above command will change all the file formats from TIFF to PNG. There are some changes that you can do with the rename command.
rename ‘y/A-Z/a-z/’
This command will change all the files from uppercase to lowercase letters.
The rename command is the best and easiest way to rename a file only if you know the above commands.
Our Opinion
These are the four ways to rename files and folders in Linux OS computers. If you are not a fan of coding, try to do all the renaming files using the first two methods. If you are coding hoodie guy, put your coding skills together and try out the last two methods. If you know any other methods to rename a file or folder in Linux, mention those in the comments section and let us know.
If you have queries or feedback, tell us through the comment section below. To get regular updates, follow us on Twitter and Facebook.