1. Home
  2. Linux
  3. Rename directory linux

How to rename directory in Linux

Looking to rename a directory on your Linux PC but unsure about how to do it? This guide will help! Follow along as we go over different ways you can rename directories on Linux!

Rename directory Linux – MV 

The fastest and easiest way to rename a directory on the Linux platform is with the MV (move) tool. MV is a command-line utility, so it works on any Linux desktop environment. Best of all, MV is an essential program for all of Linux, so there is no need to install it!

To start, open up a terminal window on the Linux desktop. The keyboard shortcut Ctrl + Alt + T will launch a terminal session on most Linux desktop environments. You can also find “Terminal” in your desktop’s app menu.

Once inside of a terminal window, execute the ls command. LS (AKA list) will show everything in the directory you are currently in (which by default is your user account’s home folder).

ls

Look through the ls command output for the directory you wish to rename. If you cannot locate the directory, you will need to find its location before attempting to rename it.

For example, to rename the “Books” folder inside of /home/derrik/Documents/, you’d need first to access the “Documents” folder using the CD command below.

cd ~/Documents/

Once inside the “Documents” folder, the ls command is run to view the contents of the “Documents” folder. 

ls

Thanks to ls, we see the “Books” folder is indeed in the “Documents” folder. From here, we can rename the directory from “Books” to something else, using the mv command.

mv Books/ new-name/

To rename any directory on Linux, start with the original name of the folder and add the new name second. The rename command is as follows:

mv original-name-of-directory/ new-name-of-directory/

Rename directory Linux – CP

Using the CP command is another way to rename a directory on Linux. It is not as effortless as the MV command, but if you’re not happy with the MV command, you can go this route to rename a directory.

To start, open up a terminal. Once it is open, use the terminal to find the exact location of the folder you wish to rename. In this example, we will use the CP command to rename the “Books” directory inside of the “Documents” folder.

First, enter the “Documents” folder using the CD command. 

cd ~/Documents/

Inside the “Documents” directory, run the ls command to view the contents of the folder. 

ls

Thanks to the ls command, we can see that the “Books” directory is indeed in the “Documents” folder. From here, we can use the CP command to make a copy of the “Books” folder.

cp -r old-name/ new-name/

Once the CP command is finished creating a copy, we can delete the “Books” folder using the RM command. 

rm -rf Books/ 

When the original “Books” folder is gone, you’ll be left with a newly renamed folder. The commands to rename directories with the CP command are as follows:

cp -r Original-Folder/ New-Folder/

rm -rf Original-Folder/

Rename directory Linux – Linux File Manager

If the Linux terminal isn’t your forté, it is still possible to rename directories using the Linux file manager. There are many excellent Linux file managers on the platform, and each of them has folder renaming functionality. 

As there are just so many Linux file managers out there for various desktop environments, we cannot go over how to rename a directory with each and every one. That said, Linux file managers are very similar, so these instructions should work on most of them.

On most Linux file managers, the F2 key allows the user to rename a directory. To rename a folder in your Linux PC with the Linux file manager, do the following.

First, locate the directory in which you wish to rename. This example will rename the “Books” folder located in the “Documents” directory in the home folder.

After locating the “Books” folder in the Linux file manager, select it with the mouse. From here, you can press the F2 key on the keyboard. Remember, the folder must be selected with the mouse BEFORE pressing F2 for this to work.

Once you’ve pressed the F2 button, the Linux file manager will prompt you to enter a new name for the directory. Using the keyboard, write out a new name using the keyboard.

Note: Don’t want to press the F2 key? Right-click on the desired folder, and locate the “rename” option in the right-click menu to rename it using the file manager.

When you’ve finished writing in a new name for the directory, press the Enter key on the keyboard. Pressing this button will apply the changes to the new folder. Repeat this to rename as many directories on your Linux PC as needed.