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
160GB! A massive hard drive boost for PS3
Yeah! It’s, indeed, surprising. Not even a month has passed when Sony announced its 80GB version of the PlayStation 3 and now there is a console with a 160GB hard drive. Surprising, but Sony is quite habitual to give surprises that’s why no wonder.
Apple released iOS 15.5, iPadOS 15.5 and macOS 12.4
Apple has released updates to its mobile platforms, iOS 15.5 and iPadOS 15.5. This is the fifth major update for iOS 15 and iPadOS 15 operating systems, originally released in September 2021.
How To Install KeePass on Ubuntu
Are you looking for a secure and reliable password manager for your Ubuntu system? Look no further than KeePass! In this comprehensive tutorial, we will guide you through the process of installing KeePass on Ubuntu from start to finish.
Belgain Court fines Yahoo
A Belgain court has fined Yahoo for withholding personal account information that relates to email addresses of Yahoo.