LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to delete all empty folders (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-delete-all-empty-folders-812652/)

rjo98 06-07-2010 09: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 09:44 AM

Hello rjo98,

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

Code:

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 :

Code:

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

Code:

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

Code:

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

Hope it helped..

g33ky

alli_yas 06-07-2010 09:47 AM

Try this:

Code:

# 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 12:01 PM

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


All times are GMT -5. The time now is 09:33 PM.