To rename a directory in a Linux system, you can use the mv
(move) command, which is commonly used for moving files and directories, but it can also be used for renaming.
Steps to Rename a Directory:
- Open a terminal on your Linux system.
- Use the
mv
command to rename the directory:mv old-directory-name new-directory-name
old-directory-name
: The current name of the directory you want to rename.new-directory-name
: The new name you want to give to the directory.
Example:
If you have a directory named old_folder
and you want to rename it to new_folder
, you would run:
mv old_folder new_folder
Notes:
- Permissions: Ensure that you have the necessary permissions to rename the directory. If not, you may need to use
sudo
:sudo mv old_folder new_folder
- Relative and Absolute Paths: You can also use relative or absolute paths to specify the directories. For example:
mv /home/user/old_folder /home/user/new_folder
- Renaming Directories with Spaces: If the directory names contain spaces, enclose the names in quotes:
mv "old folder name" "new folder name"
Summary
- Use
mv old-directory-name new-directory-name
to rename directories. - Use
sudo
if you don’t have permission to rename the directory. - Enclose names with spaces in quotes.