How to Rename a Directory in Linux

Renaming a directory in Linux is a common task when organizing files and folders. The most commonly used method is the mv (move) command.

Note: You need appropriate permissions to rename directories, especially if they belong to another user.

1. Using the mv Command

The simplest way to rename a directory is using the mv command:

mv old_directory new_directory

2. Using Absolute Paths

If the directory is located in another path, use absolute paths:

mv /home/user/old_directory /home/user/new_directory

3. Renaming a Directory as Root

If you need administrative privileges, use sudo:

sudo mv /var/www/old_directory /var/www/new_directory

Warning: Be careful when renaming system directories as root to avoid breaking configurations.

Conclusion

Renaming directories in Linux is straightforward with the mv command. Always ensure you have the correct permissions and use absolute paths when necessary.