How to Rename a Directory in Linux

Renaming directories is a common task in Linux administration and file management. Whether you want to change the name of a directory for organizational purposes or need to update the directory’s name to reflect its contents accurately, Linux provides a simple command-line method to accomplish this. In this article, we will explore how to rename directories in Linux using the mv command.

Method: Using the mv Command
The mv command, which stands for “move,” is not only used for moving files but also for renaming them.

To rename a directory using the mv command, follow these steps:

Step 1: Open a terminal
Launch a terminal on your Linux system. 

Step 2: Navigate to the directory
Use the cd command to navigate to the location of the directory you want to rename. For example, if the directory is located in the home folder, use the following command:

 cd ~

Step 3: Rename the directory
Now, execute the mv command followed by the current name of the directory and the desired new name:

 mv current_name new_name

Replace “current_name” with the actual name of the directory you want to rename and “new_name” with the desired new name.

For instance, if you want to rename a directory named “documents” to “my_documents,” the command would look like this:

 mv documents my_documents

Step 4: Verify the renaming
To verify that the directory has been renamed successfully, you can list the contents of the current directory using the ls command:

 ls -l 

You should see the updated name of the directory in the list of files and directories.

Renaming directories in Linux is a straightforward task that can be achieved using the mv command. By following the steps outlined in this article, you now have a good understanding of how to rename directories in Linux.

Note: It’s important to ensure that you have the necessary permissions to modify directories before attempting to rename them.

Leave a comment