UNIX Command To Rename A File

How do I rename a file in UNIX using command line options?

The mv is a Unix command that renames one or more files or directories. The original filename or directory name is no longer accessible. Write permission is required on all directories and files being modified. Use the mv command to:
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 5m

  • Moves a file (i.e. gives it a different name).
  • Rename a file.

mv command syntax

You need to use the mv command to rename a file as follows:

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


Open the terminal (bash shell prompt) and type the following command to list file names:

ls -l

In this example, rename a file called data.txt to letters.txt, enter:

mv data.txt letters.txt
ls -l letters.txt

File is renamed so the following command will display an error on screen:

ls -l data.txt


ls: cannot access data.txt: No such file or directory

The following would rename a file called foo to bar, while keeping it in the current directory:

mv foo bar

Rename a directory/folder Unix command

The following would rename a directory (folder) called dir1 to dir2, while keeping it in the current directory:

mv dir1 dir2

Move a file/folder to an existing directory

The following would move a file named resume.txt, without changing its name, to an existing subdirectory called /home/nixcraft/Documents/

mv resume.txt /home/nixcraft/Documents/
## verify new file location with ls -l command ##
ls -l /home/nixcraft/Documents/
Suggested Readings:

Type the following command to read mv command man page:
man mv

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • ELie Harb Aug 25, 2011 @ 16:43

    How can i read a multiples files from MF/Cobol, whose inside programs is assigned to read “file1”.
    i am getting: 201108251343file1
    Is there an routine to added the 3 files into one file1.
    Many Thanks.

    • d Oct 21, 2011 @ 16:26

      cat 201108251343file1 201108251430file1 201108251740file1>file1

  • sevar kodi senthil May 30, 2012 @ 9:18

    it is use ful for engg

  • vishal Feb 4, 2014 @ 5:23

    Damn i copied all :P

  • Julian D. A. Wiseman May 22, 2014 @ 10:19

    Please allow a question that is surely easy. A directory has many files with names resembling DSC01234.JPG, DSC01235.JPG, DSC01236.JPG, etc. Is there a one-line command that will rename all in the directory to DSC11234.JPG, DSC11235.JPG, DSC11236.JPG, etc? That is, “DSC0” becomes “DSC1”?

    Thank you.

    • Lethe Oct 27, 2014 @ 10:30

      Probably late, but:

      rename ‘s/DSC0/DSC1/g’ *.JPG

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum