Learn how to use the Rename Command to rename files on Linux in this guide. The command offers enhanced file modification capabilities and is typically included in default Linux setups. If your system does not have it, you can install it via the Terminal.
Steps-
- For Debian, Ubuntu, Linux Mint, and their derivatives, use the below command-
sudo apt install rename - If you are using CentOS 7 or RHEL, execute the below command-
sudo yum install rename - For Arch Linux, use the following-
yay perl-rename ## or yaourt -S perl-rename - As soon as the installation is done, “rename” command can be used. Use the below syntax-
rename ‘s/old-name/new-name/’ files - For instance, we will create a new directory called “filetorename” using the mkdir command. Then, we will move to the directory and use the touch command to generate five files within it. The commands are outlined below-
mkdir filetorename
cd filetorename
touch file{1..5}.txt
ls - To view the contents of the current directory, including the five newly created files, use the ls command. If you want to rename a single file named fileA.txt, use the following command-
rename ‘s/fileA/newfileA/’ fileA.txt - To change the extensions of all files, for example, to PHP, use the following commands-
rename ‘s/.txt/.php/’ *.txt
ls - If the file you intend to rename is situated in a separate directory, ensure to include its path in the command. The command could look something like this-
rename ‘s/.txt/.php/’ FILE/PATH
In this manner, you can rename files on Linux with rename command. For the latest information, do visit our KB section.
Related Articles
How to monitor active connections and network usage on your VPSApril 20, 2024
How to monitor incoming and outgoing network connections in Linux serversApril 19, 2024
How to set the possession of an unowned DNS ZoneApril 17, 2024
How to fix “There Has Been a Critical Error on This Website” issueApril 15, 2024