How to Rename a Directory in Linux Command Line

How to Rename a Directory in Linux Command Line

Renaming a directory in Linux using the command line is a straightforward process. Here's a step-by-step guide:

1. **Open the Terminal:** First, you need to open the Terminal application. You can usually find it in your applications menu, or you can use a keyboard shortcut like `Ctrl` + `Alt` + `T`.

2. **Navigate to the Directory's Location:** Before renaming a directory, you need to navigate to the location where the directory is. Use the `cd` (change directory) command to do this. For example, if your directory is in the Documents folder, you would type:

cd ~/Documents

Replace `~/Documents` with the actual path to your directory.

3. **List the Contents (Optional):** To confirm you're in the correct location, you can list the contents of the directory using the `ls` command:

ls

4. **Rename the Directory:** To rename the directory, use the `mv` (move) command. The `mv` command is used for both moving and renaming files and directories. The syntax is:

mv oldDirectoryName newDirectoryName

Replace `oldDirectoryName` with the current name of your directory and `newDirectoryName` with the new name you wish to give it.

5. **Confirm the Change:** After renaming the directory, you can use the `ls` command again to confirm that the directory name has been changed:

ls

6. **Troubleshooting:** If you encounter an error, check the following:

   - Ensure you have the correct permissions to rename the directory.

   - Verify that the directory name you are trying to change is correct.

   - Make sure that the new directory name does not already exist in the same location.

Remember, Linux is case-sensitive, so be sure to use the correct case for directory names.