-   Linux - Newbie (
-   -   How to delete all empty folders (

rjo98 06-07-2010 08:31 AM

How to delete all empty folders
I just had a bad experience with a server, and now i have a 17GB lost+found. It appears a lot of the stuff in there are folders which are empty. Since those really serve no purpose as far as recovering data from what I can tell, is there a slick way to delete just the empty folders from my /data/lost+found folder, leaving me with just the stuff I truly need to look through?

g33ky 06-07-2010 08:44 AM

Hello rjo98,

Not sure I well understood you question, anyway, you may do :


rm -fr /data/lost+found
WARNING : this will remove everything (folders & files) into 'lost+found' and the 'lost+found' folder itself.

What about removing only the empty folders :


find 'yourbasedir_name' -depth -empty -type d -exec rmdir {} \;
That gives :


find /data/lost+found -depth -empty -type d -exec rmdir {} \;
or under /data/lost+found :


cd /data/lost+found
find * -depth -empty -type d -exec rmdir {} \;

Hope it helped..


alli_yas 06-07-2010 08:47 AM

Try this:


# find -depth -type d -empty -exec rmdir {} \;
Run from within the directory that contains the empty sub-directories you want to delete.

rjo98 06-07-2010 11:01 AM

Thanks to you both, looks like you both came to the same conclusion!

All times are GMT -5. The time now is 03:56 AM.