How To Rename File In Linux – Simple Methods

Renaming files into the Windows is pretty much simple and quick than renaming file in Linux because of the user-friendly environment. But In the Linux, it is not that simple and quick. The renaming the files into the windows is quick because of the Windows Explorer a well-known File manager as part of the desktop environment. Linux also has default file manager as part of the desktop environment. Nautilus is the default file manager in Ubuntu, Dolphin is the default file manager for Linux such as many. Changing a file name in Linux can be done by two-way, by using File Manager or CLI(Command Line Interface).

How To Rename File/ Folder in Linux

Rename Linux File Using File Manager

As you know that by using the File Manager Renaming files is quick. If you are a user of the windows 10,8 then you must be seen a rename icon in the Menu bar. Exactly same you will also see the icon into the Linux which is available into the Launch Bar.

Talking about the file manager generally has a list of places such as the home folder, the desktop, other devices and the recycle bin. You can open any folders by double clicking on them and move back up through the arrows on the toolbar.

Renaming a file or folder is the same, no matter on which Operating system are you working. Just Right click on the file or folder you want to delete or Rename. You will see the Rename options over there.

The interface will change in the different file manager, for example, Nautilus, Thunar and PCManFM displays a small window to enter the new filename whereas Dolphin and Caja let you simply type the new name over the old one.

How To Rename Files Using The Linux Command Line

You can also change or delete any file through the command line and I think you might not be surprised to know that. So, let’s take a look at How it will work:

Step 1:  To get to the access of Terminal you need to open it by pressing the “Ctrl+ALT+T” and it will open the Command Line Interface for you. No matter what Linux Distribution are you using you can access the Command Line Interface by this way. Now you have the CLI.

Step 2: The Rename Command works under the “/usr/bin/” directory, so you have to copy the file into this folder or change the directory by using the “cd..” command.

Step 3: Now the syntax for renaming a file is

Use of Rename Command
rename oldfile name New File Name

You might be thinking that Rename Command is as simple as it looks but let me make it very clear it’s not like that. Here is why the old file name you entered is very much specific otherwise it will change all the file name by the new file name whoever have that name.

For example, if you have some files named as “Laptop” Now you want to change it by the “New Laptop”. So the syntax will be “rename Laptop New Laptop”. 

This is the Basic Syntax of the Rename command in case if you have to change the all file name in the Folder name then this Rename command would not be a great choice so what’s that.

Rename command comes with few optional arguments along with the mandatory perl expression that guides rename command to do work and it will Rename the files in bulk.

  1. -v: Print names of files successfully renamed.
  2. -n: Show what files would have been renamed.
  3. -f: Force overwrites existing files.
  4. -l: List All files
  5. perlexpr: Perl Expression.

Suppose you’ve bunch of files with “.jpeg” format and you want to rename all “.jpeg” files to “.jpg” at one go. For example, first, do a “ls -l” to check the list of files with “.jpeg” extension.

“~$ ls -l” This syntax will make the list of all the Files whether it contains “.jpeg” or not now all you have to convert the “.jpeg” to “.jpg”. for that syntax will be as follow:

Rename The Files in Bulk
~$ rename ‘s/\.jpeg$/\.jpg/’ *.jpeg

The above command will change the all “.jpeg” files to the “.jpg” format to make sure it is converted or not you can again use the list command which is given above.

By using the  “-n” argument with the rename command you can check the changes that you are going to made and what it will take effect. It will only show you what changes are going to do not change that. Here, is the example of the command below.

Use of Argument
~$ rename -n ‘s/\.jpeg$/\.jpg/’ *.jpeg

Find the File and Rename It

Sometimes we don’t have time to find the file and then rename it, or we forgot where is the file also don’t have time to search that. So, here is the use of the find command to find a specific file and rename it:

Find Command With Rename
find -type f -name ‘*.jpeg’ | rename ‘s/college/collegefriends/

For all files with the extension “.jpeg“, if they contain the string “college”, replace it with “collegefriends“.

So, that it guys these are the most productive ways to rename the file by using the File manager and Command Line interface. If you have any other way to do it which saves your time and effort then do let us know. we will love to address that to our reader.

LEAVE A REPLY

Please enter your comment!
Please enter your name here