In Linux and Unix-like systems, we are always amazed to see several ways for a single operation. Whether to install something or to perform through the command-line, you will get multiple utilities and commands.

Even if you want to move, copy or rename a directory, it is quite handy to perform these functions with commands; you don’t need to install any specific tool.

In Linux distributions, everything is in the form of directories. So, it is good to keep all of them in a structured way. Sometimes, we need to create temporary folders to save data and later on, to keep them permanently, we have to rename those directories.

There are no traditional commands to rename a folder/directory; it can be done using several ways. We will discuss in this guide how to change the directory name using the “mv” command and “rename” command. It might shock you that this operation can be performed using the “mv” command. The “mv” command is not only used to move one directory to another; it is a multi-purpose command which helps to rename a directory as well.

So, let’s check how we can do use the “mv” command and “rename” command:

How to Rename a Folder Through “mv” Command

To rename a folder through the “mv” command is the simplest way you have ever seen.

Create a directory in the terminal named “temp”:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-01.png" data-lazy- height="75" src="data:image/svg xml,” width=”974″>

To move the “temp” directory, make another directory with the name “temp 2”:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-02.png" data-lazy- height="66" src="data:image/svg xml,” width=”974″>

You can see in the home directory, two directories with the given names are created:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-03.png" data-lazy- height="508" src="data:image/svg xml,” width=”777″>

Now, move the “temp” to the “temp2” directory using the “mv” command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-04.png" data-lazy- height="66" src="data:image/svg xml,” width=”974″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-05.png" data-lazy- height="489" src="data:image/svg xml,” width=”752″>

Open the “temp 2” directory to check if the “temp” directory is successfully moved:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-06.png" data-lazy- height="493" src="data:image/svg xml,” width=”758″>

After moving, use the “mv” command again to rename a “temp2” directory:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-07.png" data-lazy- height="72" src="data:image/svg xml,” width=”974″>

So, the temp2 directory has been renamed successfully to the “new_Dir” directory:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-08.png" data-lazy- height="502" src="data:image/svg xml,” width=”775″>

You can also confirm it using a terminal to active a “new_Dir” directory in it, and check if the “temp” directory (we created first and moved to temp2 folder is present in the “new_Dir” directory or not):

To activate a “new_Dir” folder in the terminal, use the “cd” command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-09.png" data-lazy- height="60" src="data:image/svg xml,” width=”974″>

Now, to display the list of files present in the “new_Dir” folder, type the “ls” command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-10.png" data-lazy- height="110" src="data:image/svg xml,” width=”974″>

How to Rename a Folder Through “rename” Command

The “rename” command is a built-in tool in most Linux distributions that helps to rename folders and directories. It uses regular expressions to perform functions.

If it is not present in your system. Use the following command:

$ sudo apt install rename

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-11.png" data-lazy- height="60" src="data:image/svg xml,” width=”974″>

The syntax used for the “rename” command is:

$ rename

Consider the given examples to check if it’s working:

Example 1:

To rename the directories from lowercase to uppercase, run the ls command to display directories in the desktop directory:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-12.png" data-lazy- height="100" src="data:image/svg xml,” width=”974″>

Use the rename command with the following expressions to change letter case:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-13.png" data-lazy- height="66" src="data:image/svg xml,” width=”974″>

To confirm it, type “ls” again:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-14.png" data-lazy- height="91" src="data:image/svg xml,” width=”974″>

Example 2:

To rename the text files present in the desktop directory as pdf files, run the command:

$ rename ‘s/.txt$/.pdf/’ *.txt

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-15.png" data-lazy- height="70" src="data:image/svg xml,” width=”974″>

Type the “ls” command to display the output:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-16.png" data-lazy- height="95" src="data:image/svg xml,” width=”974″>

You can also rename a directory through GUI by simply right click on the desired folder and navigate to the “rename” option:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-17.png" data-lazy- height="495" src="data:image/svg xml,” width=”868″>

Click on the “rename” option, type the name you want to update, and click to the “rename” button:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-18.png" data-lazy- height="529" src="data:image/svg xml,” width=”812″>

And the directory name will be changed:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/Rename-Directory-Linux-19.png" data-lazy- height="545" src="data:image/svg xml,” width=”839″>

Conclusion

In this write-up, we have seen how to rename a directory in Linux operating system. There are multiple ways to do it, but why choose a difficult way when the simplest approach is available.

We have learned from this guide to rename directories using the “mv” command and “rename” command. The “mv” command is considered a multi-tasking command tool whereas, using the “rename” command directories can be changed through regular expressions. We have also checked it through the GUI approach.