Votes: 0Posted On: May 23, 2017 06:22:54
A file in linux can be renamed by using multiple methods. Here are some of the important methods used to rename a file in linux.
The "mv" (move) command
The "mv" command in linux can be used to move as well as rename a file in linux. Suppose you want to rename a file you just have to move the file to the same directory using a different name. Let us demonstrate this with an example.
Imagine you have a file named "file1" in the directory "document". You want to rename this file as "file2". Run the following command in your terminal.
mv file1 file2
The syntax of "mv" command is :
mv "old file name" "new file name"
Some options that can be used with the "mv" command are :
1. Verbose (-v)
mv -v "old file name" "new file name"
This is the verbose option that will display what task the command has performed.
Sample output -
2. Interactive (-i)
mv -i "old file name" "new file name"
This option will prompt you before making any changes.
The "rename" Command
The "rename" command can be used to rename multiple files.
Its syntax is given as :
rename 's/old_name/new_name' files
rename -[options] 's/old_name/new_name' files
Suppose you want to change all ".jpg" files to ".jpeg" files you simply run the following command.
rename 's/jpg/jpeg/' *.jpg
These were two basic commands used to rename a file in linux. These commands come with a variety of options. Once you get the basic understanding you can move on to complex options.