Rename Directories in Linux Mint 20 - The Best way ?

To maintain a structured file system is a necessity rather than a recommendation for system administrators. 

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries on Linux Mint.

In this context, we shall look into how to rename your directories in Linux Mint 20 to organize your files.


How to find your current Working Directory in Linux Mint?

To begin, you will need your directory path/name to follow this tutorial. In case you do not know your current directory, run the following command in the terminal:

$ pwd


How to List Directories / Files in Your Current Directory in Linux Mint?

In order to list all the directories and files in your current directory and verify the renamed directories with the following command:

$ ls


How to Rename Directories Using mv Command in Linux Mint?

To change your directory name, use the following mv command with your source and target directory:

$ mv <source_directory> <target_directory>


How to Rename Directories Using rename Command in Linux Mint?

Also, you can use the rename command to rename directories which is a more detailed built-in command.

To change a directory name, run the following command:

$ rename 's/<old-name>/<new-name>/' *

Rename command can be used to rename multiple directories and files names at once. For example, you can change all the directory's names to lowercase with the following command:

$ rename 'y/A-Z/a-z/' *


How to Rename multiple Directories With find Command in Linux Mint?

For more complex renaming purposes, you can use the find command in combination with mv and rename command.

Note: mv command can only rename a single directory at a time. To make multiple changes you need to run it in combination with the find command.

Run the following command to change a directory name:

$ find . -depth -type d -name <source_directory> -execdir mv {} <target_directory> \;

Here, '-type' option will look for the directory while '-exexdir' option will let the directory be renamed with mv command.

You can make filesystem-wide directory changes with the find command. It comes in handy in particular, when you do not know where your targeted directory lies.

In the command below, the find command is run in combination with the rename command to change all directory names to lowercase:

$ find . -mindepth 1 -prune -type d | rename 'y/A-Z/a-z/'


[Need help in fixing Linux System issues? We can help you. ]

This article covers the best methods to organize your directories in your Linux Mint system. Keeping an organized file system brings merit not only to system administrators, but regular users can also benefit from it.

To rename a directory on Linux, use the "mv" command and specify the directory to be renamed as well as the destination for your directory. To rename this directory, you would use the "mv" command and specify the two directory names.

Related Posts