//View Tip #181
Similar Tips
» Finding log files X number of days old and deleteing them.
» Overwrite a file with zeroes
» Rename many files using find and perl
» Version all unversioned files in an SVN checkout
» The poor man's REPL


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
To remove empty directories (even if filenames or dirnames contain spaces or weird characters) from a tree you can do:

find . -type d -empty -print0 | xargs -0 rmdir

View Comments »


Add your comment

Comments are currently disabled
drop that stupid xargs and just use find's -delete

 find . -type d -empty -delete

or if you have an old version of find:

 find . -type d -empty -exec rmdir {} ';'
Posted 2009-02-13 19:51:40
I would not recommend this. Some programs my have empty directories setup for variable data like stuff in var. Removing them could cause problems. If you limited this to the /home directory then that would be alright.  If you have issues with multiple empty directories just cropping up out of no where I would search for intrusion.
Posted 2010-01-05 19:08:28

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit