How To Rename Files & Directories in Linux

In this comprehensive tutorial, we will delve into the intricacies of renaming files and directories in Linux using the terminal. While graphical options are often the preferred method for renaming a single file, there are times when we need to do it from the terminal. Additionally, when we need to rename multiple files, using the terminal can be more efficient than doing so manually.
Throughout this tutorial, we will explore two different commands that can be used to rename files and directories in Linux: mv and rename. By following these simple steps, you will quickly realize that renaming files and directories in Linux is not as complicated as it may seem.
Whether you are a seasoned Linux user or just starting out, this tutorial will provide you with all the knowledge you need to effectively rename your files and directories with ease. So, let's get started and discover the power of the terminal when it comes to renaming files in Linux. Remember, practice makes perfect!
MV command to rename file or Linux directory
To rename a simple file or directory we use the following:
mv current_file_name new_file_name
If we want to change the extension of several files at the same time, because they have one that we do not want, instead of doing it one by one, we can execute:
mv *.CurrentExtension *.extensionNew
Maybe with some examples, it looks better.
Examples
We want to change the name of the Linux folder to Linuxcode:
mv Linux Linuxcode
We want to change the extensions of all the files in the directory we are in (the change will be from png to jpg):
mv *.png *.jpg
This way of renaming is very easy to use, but the next option that we will see is more powerful.
Command RENAME to rename Linux files
To see the use of the rename command, we will do it directly with examples, because it will be better understood.
If we want to change from extension .txt to .bak:
rename 's/\.txt$/\.bak/' *.txt
If we’re going to remove the 2016 text from some photos with jpg extension:
rename 's/ 2016//g' *.jpg
If we’re going to convert all uppercase letters to all names:
rename y/A-Z/a-z/ *.extension_files
If you want it the other way around, it is to pass lower case to uppercase merely change y/A-Z/a-z/ to y/a-z/A-Z/.
The way to do it in these cases (in Ubuntu):
sudo rename 's/\.db$/\.bak/' *.db
It might be interesting
How To Check Meltdown or Specter Vulnerability on Linux
The processor has been infiltrated by vulnerabilities, known as Specter and Meltdown, which enable an attacker with sufficient knowledge to gain unauthorized access to the processor and obtain sensitive information such as passwords.
WIN! A PS3 Slim and Batman: Arkham Asylum
It is official; Sony is finally launching its latest PS3 slim edition next month at the GamesCom event in Cologne and you can win this year’s favourite Christmas present before anyone else on TechRadar.
Pre-order pricing for Nokia N97 flagship device
At last the Nokia shop has offered a pre-order price for the Nokia N97 and there is no more long build-ups for the release of a mobile phone.
Tencent: The largest internet portal in China
instant messenger is the product that gives recognition to Tencent which is the largest internet portal in China. Recently, they have reported about the number of users on its QZone social networking service.