How to rename directories?

QuestionsQuestions8 SkillsProBasic Files OperationsAug, 05 2025
0166

Renaming directories in Linux is similar to renaming files and can be accomplished using the mv command. Here’s how to do it:

Basic Syntax

mv OLD_DIRECTORY_NAME NEW_DIRECTORY_NAME

Example of Renaming a Directory

  1. Renaming a Directory:
    If you want to rename a directory called old_directory to new_directory, you would use:

    mv old_directory new_directory
  2. Renaming a Directory in a Different Path:
    If the directory is located in a different path, you can specify the full path:

    mv /path/to/old_directory /path/to/new_directory

Important Notes

  • If a directory with the new name already exists, it will be overwritten without warning unless you use the -i option to prompt before overwriting:

    mv -i old_directory new_directory
  • Ensure you have the necessary permissions to rename the directory.

Summary

Renaming a directory in Linux is straightforward using the mv command. Just specify the current directory name and the new directory name, and the directory will be renamed.

If you have any more questions or need further assistance, feel free to ask!

0 Comments

no data
Be the first to share your comment!