Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
6  
Are you thinking about starting from /? Because if so, don't do that. –  Aaron Miller Oct 3 '13 at 17:15
1  
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
3  
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... –  DocSalvage Oct 10 '13 at 21:24
add comment

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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