How to rename file in Linux (Easy Method)

The renaming file is an easy task unless you have to rename a bundle of files or folder in a go. Well, that is also quite easy using Linux command-line interference. Yeh, you read that right; using commands, you can rename batch files.

Not only the command, but you can also rename the files using some Linux programs. We will discuss all the software and commands that can rename the files in no time and effort. So, we have divided the article into two parts. In the first part, we will discuss the commands that we can use, and in the 2nd part, we will talk about the programs that you can use to rename files in Linux.

How to Rename Files in the Terminal?

Rename files in Terminal
Rename files in Terminal

As a Linux user, you know the power of terminal, you can do multiple extraordinary operations using commands and quickly too. So here are some commands for renaming the files.

Renaming files using the “rename” command

This is a bit difficult, or you can say you must have some knowledge for regular expressions to apply this command. But don’t worry if you are not familiar with them. You will get step by step instructions in this guide.

The general command that you have to type is given below.

rename (option)'s/oldname/newname/' file1.ext file24.ext

Now to apply this, you have to learn, for what purpose, each of the above command words is used. In the single quotes, s stands for the ‘substitute”- a function of regular expressions. You have to rename the old name with the file name you want to rename and newname with the name you want to assign for that file.

Now in the options part, you have a couple of options available that you can apply to see what works.

  • (-n). First of all, as this is a bit complicated command, you can check if the files you are going to rename are the files that you want to remove. To check that out, you can apply the option (-n) in the options brackets. By doing so, you can check the files, without making any changes.
  • (-v). This action stands for the verbose. You can use this command if you want to print the old and new names of assigned files.
  • (-f). Using this option, you can do a forced overwrite the original files.

Renaming files of same type or extension

Using rename command, you can also rename the files that are of the same types or even the same extensions. For this, you have to modify the command with the extension name, and you are good to go. For example,

rename 's/.jpeg/.jpg/'*

command can be used to rename all the files with jpeg and jpg extensions. The * symbol is used to target all the files in the folder; it is called the wildcard symbol.

Applying the modifiers

You can also use the modifiers to make further changes with the files using the rename command. The following are the modifiers and their functions.

  • G- affects all the files with the name given.
  •  I- is used for case-sensitive operations (for capital or small letters)

Now using the above modifiers, the command can become,

rename -v's/DSC/photo/gi'*.jpg

Using this command will change all the jpg file names having DSC in them with photos. It will also target the file names with DSc, DSC, or dsc because we have used the case-sensitive modifier.

For example, if the file has the name “Jane-DSC.jpg,” then that will be changed to “Jane-photo.jpg.”

It is quite easy, right! But if you are not that sure about renaming, you can also use the -n option to see the files that are going to be renamed.

Changing Lower-case to lowercase and vice versa.

You can also change the lowercase letters in the name of the file to the upper-case, and also, you turn the uppercase letters into lowercase. ‘ Y ‘ is the substitute that is used to change the file name on a sophisticated level. You can use that in the following way in rename command.

rename 'y/a-z/A-Z/'*.jpg

Without using any option, apply this command. This will target all the jpg files in the folder and will change the lowercase letter to upper-case.

In the same way, if you want to change the uppercase to the lowercase, put A-Z before the slash and a-z after the slash. You are good to go.

Using the “MV” command

This one is quite easy, and you can apply this without any expressions understandings. You may be thinking that mv is the command to move files, how can we use that to rename files? Well, you can.

Use the following command line to execute the file rename function.

mv(option) filename1.ext filename2.ext

In the above command, filename1.ext is the old name of the file with ext (extension), while the filename2.ext is the new name of the data that you want to rename.

The same goes for the files in the specified folders. You have to specify the folder in which the data are placed. You can do this by using the same command

mv/home/administrator/Files/filename1.ext /home/administrator/Files/filename2.ext

In this way, the filename1.ext will be renamed to filename2.ext in the files folder of admin.

Prerequisites: You must keep in mind that the mv command requires writing permissions for the files. So, before applying this command, just turn on the permissions for that folder. If you are going to rename the system files or folders, in that case, you need root permissions. For that, you have to apply the su or sudo command. If you are a little bit skeptical, then you can also use the command -i so that you can confirm the change after applying command.

Rename file in Linux using Software

Here are some Linux programs that you can use in Ubuntu to rename files. Use any of the programs below. And let us know in the comments which one do you like the most.

Rename files using KRename

KRename
KRename

This has pretty simple interference with tabs that are easy to navigate. You can use this software to rename the file names in bulk. You just have to select the folder, and then the file extensions with an old and new name. The Krename will handle the rest of the task.

It comes with plugins with extra features. Thus plugins are its real power. One of its most powerful features is translating from one language to another language.

You can install the Krename by using Sudo apt-get install krename command in your Ubuntu.

Rename files using pyRenamer

pyRenamer
pyRenamer

If you want to use the power of mv and rename command in software, then pyRenamer is there for you.

This is the easiest way to do the renaming of multiple files using simple software. This is primarily for non-console users. They can easily do the renaming of the files in a few clicks. Not only the simple renaming, but you can also do some potent functions using pyRenamer, including renaming the photos or files according to date and time. Adding artist name or title in the track name, or sorting the documents according to the time they were captured.

Seem interesting! Not just that, pRenamer has very user-friendly interference. Here is the method to operate this program.

pyRenamer Steps
pyRenamer Steps

Here are the parts of the main screen. In the above screen, the left portion number 1 is a tree view of the files and folders from your computer. The central area number 2 is for the list of the files before and after changing names.

Number 3 portion is for the renaming criteria, and the number 4 is the options bar.

pyRenamer Functions
pyRenamer Functions

The following are some of the functions that can be performed by the pyRenamer.

  • Change the name of the files in a single click.
  • It can also change the file extensions.
  • It can change the lowercase letters to lowercase letters and vice versa.
  • You can change the filename according to the date.

This call can be done using pyRenamer, pretty quickly.

Renaming files using File Manager

File Manager
File Manager

If you do not want to install any other software, then you can do the job, too, using the inbuilt file manager. Just select the files, and right-click on them. Now, navigate towards the rename option. Here you can rename the files without using any commands or terminal.

But if you do not have the GNOME interference of Linux, then, unfortunately, you can not edit the multiple files using file manager. Yet you can use the programs mentioned above and the commands to rename multiple files.

Conclusion

Renaming multiple files at once can be a really tough deal. But using this guide, you can rename files in Linux using simple software or terminal. Please let us know in the comments about which type of method you like the most of renaming the files in Linux.

Related Posts