How to rename a directory using Command Line Terminal

If you have a directory on your Ubuntu Linux, Unix, or macOS system and you want to rename it via the command line Terminal, you can make use of the mv - move files command.

Syntax:

mv dir-name renamed-dir

Let's take a look at a few examples:

Example 1:

Let's say you have a directory named mydir in the current directory and you want to rename it to mydir_archive.

% mv mydir mydir_archive
How to rename a directory using Command Line Terminal

Example 2:

Let's say you have a directory named mydir directory somewhere and you want to rename it to mydir_archive. In this case, you need to provide the absolute paths.

% mv /Users/c2ctech/desktop/mydir /Users/c2ctech/desktop/mydir_archive

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!