//View Tip #181
Similar Tips
» Moved Trac and Subversion repositories to another machine/direct
» My code is compiling
» Copy and paste from the command line
» Version all unversioned files in an SVN checkout
» Find occurrences of a string in a large code base without firing

 

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 »




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
Treah
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