Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Are you thinking about starting from /? Because if so, don't do that. – Aaron Miller Oct 3 '13 at 17:15
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
Just trying to keep a tidy filesystem – Demetri Oct 4 '13 at 0:00
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.

share|improve this answer
I certainly was only planning to remove empty directories. – Demetri Oct 16 '13 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .