Jump to content

How to Rename a Directory in Linux


Linux Hint

Recommended Posts

Directories in Linux are folders that are used to store and organize the files. You can nest the directories, modify their permissions, create shortcut links to them, and more. Among these many features, you can also modify the name of a directory which is a fundamental task of Linux users. Moreover, it is essential to rename a directory to ensure an easy access and structurize the data.

Users often create temporary directories. But due to obvious reasons, they need to rename them later. However, many of them are unaware of the method that is used for this process. Don’t worry if you’re one of them because this guide will briefly discuss how to rename a directory in Linux.

How to Rename a Directory in Linux

Renaming a directory is easy in Linux. You can do it using a simple “mv” command in the following syntax:

mv [old directory name] [new directory name]

Before using this command, navigate to the parent directory of the targeted directory. Otherwise, the command won’t work. After that, check the contents of that directory using the “ls” command to verify that the targeted directory exists inside it.

Directory-in-Linux-1.png

For example, as you can see in the previous image, we have a directory named “Temp_Directory”. So, let’s rename it to “Scripts”.

mv Temp_Directory Scripts

The “mv” command does not show anything upon a successful execution. Therefore, use the “ls” command again to verify the changes.

Directory-in-Linux-2.png

Note: If the renamed directory was initially referenced somewhere, such as in a script or some configuration, update these references accordingly to avoid future errors.

Conclusion

The process of renaming the directories is straightforward. So, this guide briefly explains how to rename a directory in Linux. It starts with navigating to the parent directory, then using the “mv” command to rename the targeted directory, and finally verifying the changes. Furthermore, the users can efficiently rename their directories by following the process to maintain an organized and well-structured file system.

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...