Using the find command, it is easy to recursively delete all empty directories. Which empty directories are safe to delete, and which ones are not?

  • 7
    Are you thinking about starting from /? Because if so, don't do that. – Aaron Miller Oct 3 '13 at 17:15
  • 2
    Doing this indiscriminately sounds like a great way to hose your system. – Nanzikambe Oct 3 '13 at 17:30
  • Why would you need to do this? – Aaron Copley Oct 3 '13 at 18:27
  • 1
    Just trying to keep a tidy filesystem – Demi Oct 4 '13 at 0:00
  • 5
    There are typically hundreds of empty directories on a Linux system because most software saves code and time by assuming the existence of most directories, which is pretty standardized. The only directories typically tested for existence before using are those created by the program. Doing what you propose will hose your system. Take it from someone who's done it... – DocSalvager Oct 10 '13 at 21:24

You can recursively delete directories in which you put your data (like Documents, Videos, Images, Downloads, etc.), the others into your home directory (e.g. .cache, .gnome, , .ssh), your root, its sub-folders, etc., shouldn't be removed in this way!

A useful and quite safe way to do this is using the rmdir command (with find):

find . -empty -type d -exec rmdir {} +

It starts in the current working directory.

  • I certainly was only planning to remove empty directories. – Demi Oct 16 '13 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.