How to rename a directory in Linux? It’s also one of the most asked questions by Linux beginners.
It’s a very basic operations, if you’re using a graphical file manager like Dolphin or Nautilus. But that’s not always not possible.
So here’s how you can rename folder in linux with basic command line tools.
Rename directory linux with mv command
The mv command has many use, could be used to rename files or move them to different location.
Below the generic way to rename folder in linux with the mv,
mv old_directory new_directory
Of course you need read write permission on that particular directory to rename it. So if you’re facing a Permission denied error, use
sudo mv old_directory new_directory
Now some useful argument to use along with the
-n, don’t overwrite an existing file.
-i, prompt before overwrite
-f, force overwrite, no prompt
-u, rename or move only when source file is newer than destination file, or missing.
-u options are useful when you’re dealing with large number of directories, and don’t want to rewrite the existing directories.
You also have to take care of proper path when you’re dealing with directories not located in the current working directory.
Example: Assume you’ve a directory under the Documents directory, you want to rename it to logos_new, but you’re currently at home(~/) directory.
mv /home/user/Documents/logos/ /home/user/Documents/logos_new
Have a look at the animation on top for more details.
So, that’s all about how you can rename directory linux, it’s very simple with the mv command.
You just have to take care of proper permission and carefully use sudo when needed. You can learn more about mv command here.
That’s the third installment of the linux for beginners series, read the first two below.
If you’ve any question or suggestion, please feel to leave comments, also don’t forget to share this tutorial with your Linux loving friends.