Rename Directory Linux - 4 Easy Methods

Reading time icon 3 min. read


Readers help support MSPoweruser. When you make a purchase using links on our site, we may earn an affiliate commission. Tooltip Icon

Read the affiliate disclosure page to find out how can you help MSPoweruser effortlessly and without spending any money. Read more

rename directory linux

Want to rename a directory on Linux? It’s crucial for maintaining an organized file structure.

In this guide, I’ll discuss 4 simple methods to achieve this. Let’s go!

How To Rename a Directory on Linux

To rename a directory on Linux, you can use:

  • mv command
  • rename command
  • find command
  • File Manager (GUI method)

1. mv Command

In Linux-based operating system, the mv command is primarily designed to move files and directories. However, you can also utilize it to rename directories.

1. Press CTRL+ALT+T to open the terminal.

2. Run cd to navigate to the parent directory of the one that you want to rename.

moving to another directory on Linux wih cd command

3. List the content of the current directory with ls.

listing content of current directory on Linux with ls command

4. Type “mv old_directory_name new_directory_name” to rename the desired directory. In my case, I’ll rename the “important_files” directory as “tests”.

Renaming a directory on Linux using mv command

5. For verification, again execute ls.

verify directory rename operation on linux

2. rename Command

rename command is a Linux utility that’s specifically designed for batch renaming of files and directories. Moreover, it supports regular expressions to perform complex renaming tasks across multiple files.

1. First, install rename with “sudo apt install rename“.

2. Then, type “rename ‘s/old_directory_name/new_directory_name/’ *”.

renaming a directory on linux using rename command

In the above command, “‘s/old_directory_name/new_directory_name/’ *” is a regular expression, where:

  • s/ represents a substitution operation.
  • old_directory_name indicates the original pattern or name that you want to replace.
  • new_directory_name is the replacement pattern or new name.
  • * is a wildcard character that refers to all files and directories in the current directory.

3. find Command

The find command can locate files based on the specified criteria. In addition, you can combine it with the mv command to rename a directory when you don’t know its exact location.

For this, type “find . -depth -type d -name old_directory_name -execdir mv {} new_directory_name \;” and hit Enter.

Renaming a directory on Linux using find command

Here:

  • find . searches starts the search from the current directory.
  • -depth processes directory contents before the directory itself.
  • -type d instructs find command to include only directories.
  • -name old_directory_name searches for the specified directory.
  • -execdir executes the mv command for each matched directory.
  • {} is a placeholder for the current directory name, replaced with the actual name during execution.
  • \; indicates the end of the -execdir option.

4. File Manager (GUI Method)

You can also try File Manager if you aren’t comfortable with the command-line interface:

1. Open the Activities menu and type “Files“.

Opening File Manager on Linux

2. Move to the directory location.

Move to the location of desired directory

3. Right-click on the desired directory and select the “Rename” option from the context menu.

selecting the desired directory to rename it

4. Type the new name and hit Enter.

renaming the selected directory using GUI

5. Verify.

verify the new name of the selected directory

You may also be interested in:

So, now you know all essential rename directory Linux methods. Feel free to share your favorite approach in the comments below!

More about the topics: linux