Renaming a directory in Linux can be easily done from the command line using the mv command. The mv command is a command-line utility that allows you to move and rename files and directories.
To rename a directory using the mv command, follow these steps:
- Open a terminal window. On most Linux distributions, you can do this by pressing Ctrl+Alt+T on your keyboard.
- Navigate to the directory that contains the directory you want to rename. You can use the cd command to change directories. For example, if the directory you want to rename is located in your home directory, you can use the following command:
cd ~
- Now use the ls command to list the contents of the current directory. This will show you the name of the directory you want to rename, as well as the names of any other files or directories in the same directory.
- Then use the mv command to rename the directory. The syntax for the mv command is as follows:
mv old_directory_name new_directory_name
Replace old_directory_name with the current name of the directory, and new_directory_name with the new name you want to give the directory. For example, if the current name of the directory is old_dir and you want to rename it to new_dir, you would use the following command:
mv old_dir new_dir
- You can use the ls command again to verify if the directory has been renamed.
Here’s an example of how to rename a directory using the mv command on popular Linux distributions:
Ubuntu
To rename a directory on Ubuntu, open a terminal window and use the cd and mv commands as described above. For example, to rename a directory named old_dir to new_dir in your home directory, you would use the following commands:
cd ~ mv old_dir new_dir
Fedora
To rename a directory on Fedora, open a terminal window and use the cd and mv commands as described above. For example, to rename a directory named old_dir to new_dir in your home directory, you would use the following commands:
cd ~ mv old_dir new_dir
Debian
To rename a directory on Debian, open a terminal window and use the cd and mv commands as described above. For example, to rename a directory named old_dir to new_dir in your home directory, you would use the following commands:
cd ~ mv old_dir new_dir
In conclusion, renaming a directory in Linux is a simple task that can be easily accomplished from the command line using the mv command. Whether you’re using Ubuntu, Fedora, Debian, or any other Linux distribution, the steps for renaming a directory are the same.
But if you are looking in how to rename a file in linux then follow this post.