Unix Command To Rename A Folder

How do I rename a folder under UNIX operating systems using a command line tools?

You need to use the mv command to rename a folder under UNIX operating systems. You must have write permission for all folders.

Syntax to rename a directory on Unix

The syntax is as follows:
mv old-folder-name new-folder-name

OR

mv /path/to/old /path/to/new

Example: Unix rename a directory command

In this example, a folder called drivers is renamed as olddrivers. Open a terminal (shell prompt) and type the following commands:

ls
mv drivers oldrivers 
ls

ls
mv drivers oldrivers
ls

OR pass the -v option to get verbose output:

ls
mv -v drivers oldrivers 
ls

ls
mv -v drivers oldrivers
ls

Do not prompt for confirmation before overwriting

mv -f dir1 dir2

mv -f dir1 dir2

Prompt for confirmation before overwriting

mv -i dir1 dir2

mv -i dir1 dir2

Pass the -n option to mv command to do not overwrite an existing file/dirname. The -n option overrides any previous -f or -i options:

mv -n dir1 dir2

mv -n dir1 dir2

Recommend readings

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.