Linux Rename File Command

by on May 6, 2011 · 7 comments· LAST UPDATED May 6, 2012

in

I'm a new Linux user. How do I rename a file called resumezzz.pdf to resume.pdf using Linux bash command prompt?

You need to use the mv command. It is used to rename and move files and directories. The general syntax is as follows:

 
mv old-file-name  new-file-name
mv [options] old-file-name  new-file-name
mv file1 file2
 

In this example, the following command would rename a file called resumezzz.pdf to resume.pdf. Open a command-line terminal (select Applications > Accessories > Terminal), and then type:

 
mv resumezzz.pdf resume.pdf
 

If resumezzz.pdf is located in /home/vivek/docs/files directory, type:

 
cd /home/vivek/docs/files
mv resumezzz.pdf resume.pdf
 

OR

 
mv /home/vivek/docs/files/resumezzz.pdf /home/vivek/docs/files/resume.pdf
 

Use the ls command to view files:

 
ls -l file1
ls -l file1 file2
ls -l /home/vivek/docs/files/*.pdf
ls -l *.pdf
 

Linux rename a file syntax

In short, to rename a file:

 
mv file1 file2
 

You can get verbose output i.e. mv command can explain what is being done using the following syntax:

 
mv -v file1 file2
 

Sample outputs:

`file1' -> `file2'

To make mv interactive pass the -i option. This option will prompt before overwriting file:

 
mv -i file1 file2
 

Sample outputs:

mv: overwrite `file2'? y

Detailed information about mv command

You can also view the manual page on mv using the following command:

 
man mv
 

OR

 
info mv
 
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 7 comments… read them below or add one }

1 Linux in malawi November 19, 2012 at 1:44 pm

Thank you very much. It worked

Reply

2 Nick February 6, 2014 at 3:20 pm

While the move command will work, there is actually a rename command:

rename

Which in this case would be:

rename resumezzz resume resumezzz.pdf

Reply

3 Aaron February 22, 2014 at 8:07 pm

For those of us arriving because we googled the syntax for the “rename” command in linux, this is annoying.

Reply

4 fawad April 28, 2014 at 11:50 am

thank you sir… :)

Reply

5 sri April 30, 2014 at 4:32 pm

“ls -l ” is this commend applicable for listout all..

Reply

6 akhter June 4, 2014 at 6:06 am

Thanks it’s working

Reply

7 Guest June 4, 2014 at 8:03 am

rename texttoreplace textreplacement listoffiles

If I want to remove some text I use just use “”

rename texttoremove “” *

Reply

Leave a Comment

Tagged as: , , , , , , , , , , ,

Previous Faq:

Next Faq: