PCsuggest

  • Quick tip
  • SECURITY
  • NETWORKING
  • OpenWrt
  • HARDWARE

Rename directory in Linux with command line

Updated - October 8, 2019 by Arnab Satapathi

How to rename a directory in Linux? It's also one of the most asked questions by Linux beginners.

rename directory linux demo

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.

sudo mv old_directory new_directory

Now some useful argument to use along with the mv command.

  • -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.

The -n and -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.

amazon prime logo
Try AmazonPrime for free
Enjoy free shipping and One-Day delivery, cancel any time.
mv /home/user/Documents/logos/ /home/user/Documents/logos_new

Have a look at the animation on top for more details.

Conclusion

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.

  • How to rename files in Linux
  • How to remove directory in Linux

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.

Filed Under: linux basics Tagged With: command line, rename command

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright © PCsuggest.com · All rights reserved.

  • Home
  • About
  • Contact
  • Privacy Policy
  • Sitemap