Can you rename a directory in Linux using the CLI?

Can you rename a directory in Linux using the command line options?

Yes, you can rename a directory (also called “folder”) in Linux bash shell. One need to use the mv command to rename and move files and directories or folders. Everything is a file under Linux operating system including folders.

Can you rename a directory in Linux?

The procedure to rename a directory in Linux is as follows:

  1. Open the Linux Terminal application or bash prompt
  2. Type the following Linux command to rename “delta” folder to “data”:
    mv delta data
  3. You can use full path too:
    mv /home/vivek/old-folder-name /home/vivek/new-folder-name

Let us see the mv command examples and syntax in details to rename a folder in Linux.


The pwd command shows current working directory:
Sample outputs:


The mv command syntax form is as follows:
mv old-name new-name
mv [options] old-name new-name
mv [options] source target

To rename a directory named “sales” to “SalesData” in the current directory:
ls -l
mv sales SalesData

Verify it with the ls command:
ls -l

If the SalesData folder is located in the same directory as the sales directory, then the pics directory can only be renamed. Hence always use pwd command and ls command to find out your current working directory.

Getting help about mv command on Linux

Run the following mv command at the cli to read man page of mv for all option:
man mv
mv --help

Sample outputs:

Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
      --backup[=CONTROL]       make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
  -f, --force                  do not prompt before overwriting
  -i, --interactive            prompt before overwrite
  -n, --no-clobber             do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
  -S, --suffix=SUFFIX          override the usual backup suffix
  -t, --target-directory=DIRECTORY  move all SOURCE arguments into DIRECTORY
  -T, --no-target-directory    treat DEST as a normal file
  -u, --update                 move only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
  -v, --verbose                explain what is being done
  -Z, --context                set SELinux security context of destination
                                 file to default type
      --help     display this help and exit
      --version  output version information and exit
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:
  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups
GNU coreutils online help: <>
Full documentation at: <>
or available locally via: info '(coreutils) mv invocation'


You learned how to rename a directory in Linux using the mv command. See mv help page here for more info.

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

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
1 comment… add one

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