HomeHow ToHow to Rename Files in Linux Using Command Line: Easiest Ways

How to Rename Files in Linux Using Command Line: Easiest Ways

If you are a person who is new to Linux, you might be finding it difficult to get around things. But don’t worry, getting to know Linux and using it efficiently and effectively can consume some time. So now taking the first step towards learning Linux, we will see how you can rename files in Linux.

Linux is a very popular operating system and mostly used in managing servers and data centers. One of the best reasons that Linux is developing so fast is because of the reason that it is open source. Because of the code base being open source modules, programs and even operating system components can easily be modified and reused for various another purpose.

Ways to Rename Files in Linux

You may not like user interfaces of any Linux distribution, but the fact is that all the power of Linux is hidden in it’s CLI(Command Line Interface). There are several ways to do so and so here is the list of ways to rename files in Linux:

Also read: Create Bootable Pendrive using CMD

Using Linux GUI(Graphical User Interface)

Most of the Linux distribution nowadays comes with an interactive user interface. So you can easily rename files by right-clicking on file and select the rename option just like we used to do on a windows os.

Renaming using mv (move) command

mv command is used to move files on a Linux distribution. So, you can use it rename the file by moving it to the same directory but with a different name. Here is the example of how it can be done.

mv file.txt renamedfile.txt

Renaming Files Mv Command

Renaming file using cp (copy) command

Similarly, you can first copy your file with the other name that you want to change to and then delete the original file. Here is how you can do so.

  1. First copy the file using cp command. (cp file.txt newfile.txt)
  2. Now delete the original/source file using rm command. (rm file.txt)

Renaming Files Cp Command

Protect Your Online Privacy With Surfshark
[The VPN that we use here at Tech Arrival]

Renaming multiple files at once using Regex (Regular Expression)

If you have heard about the word regular expression then probably you might know that it is used to identify the objects following the same pattern. In our case, it is renaming files that meet specific criteria.

Before jumping into commands, first of all, you must know about these two things.

  1. Wildcard (*) – * is used to specify a wildcard. For example, a*.txt means every file that is starting with the name a and having txt extension.
  2. Any Character (?) – ? is used to specify a single space for any character. For example, a?.txt means every file is having the name of length two characters, starting with an alphabet a and having txt extension.

Now let’s see how you can rename files in bulk on Linux. Suppose you have 100 doc files in a directory. Now you want to change it to docx. You can simply so that using the following command:

mv *.doc *.docx

Suppose you are renaming a file tech.txt to technology.txt, but by mistake, you changed it to technology3.txt. Now you can find that file and rename it using:

mv technology?.txt technology.txt

Bonus Tip: If you are renaming lots of files using wildcard then you should know that m command overwrites if the file with the same name already exists. So if you want confirmation before overwriting the file you can add -i in the mv command. For example, mv -i 1*.txt 2*.txt.

Renaming directory using mv command

You have to do the same thing that we did for renaming files because Linux distribution treats them as the same. You can use the command:

mv directory1 directory2

Using the rename command

As we discussed earlier regular expressions are a must known thing if you are getting into dealing with a large number of files while renaming. Rename is one of the complex and useful command which uses regular expressions to manipulate the files. So here is the syntax of a basic rename command:

rename ‘s/old/new’ files

Protect Your Online Privacy With Surfshark
[The VPN that we use here at Tech Arrival]

In the first parameter ‘s/old/new’, s stands for substitute, old stands for regular expression of old files and new for regex of new files. The second parameter is the list of files that will be processed using this command.

Without getting into more details let’s see the use of rename command which will convert all the names of the files from lowercase to uppercase of a .txt extension:

rename ‘y/a-z/A-Z/’ *.txt

Mastering advanced renaming techniques

There are lots of parameters and additional fields that can be used to perform advanced level renaming using mv/move/mmv/rename command. We can’t describe all of them here, but you can use the Linux manual command to learn more. You can type

man commandname

Man Rename

This will give the list of all the things that you can do with these commands.So these were the techniques that you can use to rename files and directories on a Linux distribution.

So these were the techniques that you can use to rename files and directories on a Linux distribution. We hope that you found this article helpful. If yes, we would appreciate if you can share this on social media and with you friends to expand their knowledge base.

Also, if you have any doubt or query with any of the things or commands that we mentioned here you can ask us using the comment section below. We will love to help you out.

“As an Amazon Associate & Affiliate Partners of several other brands we earn from qualifying purchases.” [Read More Here]

Mehul Boricha
Mehul Boricha
Mehul Boricha is the founder of Tech Arrival & Astute Links. He is a computer and smartphone geek from Junagadh, Gujarat, India. He is a Computer Engineer by Education & an Entrepreneur by Passion. Apart from technology geek, he is an audiophile & loves to connect with people.

Leave a Comment

Please enter your comment!
Please enter your name here

By submitting the above comment form, you agree to our Privacy Policy and agree with the storage and handling of your data by this website.

Stay Connected

Subscribe to our Newsletter

Stay updated with all the latest news, offers and special announcements.

By signing up, you agree to our Privacy Policy and agree with the storage and handling of your data by this website.

Latest Posts

10 Tips to Boost Your Followers & Likes on TikTok

In the ever-evolving world of social media, TikTok has emerged as a powerhouse platform that has taken the digital landscape by storm. With its...

Step-by-Step Instructions for Moving Your WordPress Site to a New Hosting Service

Moving your WordPress website to a new hosting service can be daunting. Many moving parts are involved, and it can quickly become a nightmare...

Is Passvers iOS System Recovery Safe?

When you try recovering a broken-down iOS system with a third-party iOS system recovering program, security is the priority you feel concerned about. Passvers...

What Channel is the Yankees Game on Spectrum TV?

With the Yankees game coming up, baseball fans are excited to watch their favorite team perform. Spectrum TV subscribers are lucky as they can...

TOZO Golden X1 Review: Best Earbuds Under $150?

TOZO Golden X1 are the latest wireless earbuds that we got a chance to review thoroughly. To be very honest with you guys, when...

All Time Favorites

12 Best WiFi Hacking Apps for Android & iPhone

Today, almost anywhere we go, we are surrounded by tons of WiFi Networks, whether at our homes, hotels, workplaces, or even public places like...

21 Best Android Apps Not on Google Play Store

Google Play Store has the most extensive collection of apps for Android. Almost everyone downloads apps from the Play Store. But many excellent apps...

15 Best Game Hacking Apps for Android with/without Root

Are you a mobile gamer? If you are, then you've come to the right place. This post will tell you about the Best Game...

How to Download Torrent Files with IDM (Torrent to IDM)

Hey guys, you may all have heard about different ways to download torrent files. And some of you may also have downloaded them using...

11 Best Download Managers for Windows

The Internet is a vast resource of a lot of things which includes music, videos, movies and a lot of other things. The ability...