LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2010, 08:31 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
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?
 
Old 06-07-2010, 08:44 AM   #2
g33ky
Member
 
Registered: Jun 2010
Location: France
Distribution: openSUSE 11.2, (B)LFS, Mepis, Linux Mint 9
Posts: 30

Rep: Reputation: 17
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

Last edited by g33ky; 06-07-2010 at 08:50 AM.
 
Old 06-07-2010, 08:47 AM   #3
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
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.
 
Old 06-07-2010, 11:01 AM   #4
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
Thanks to you both, looks like you both came to the same conclusion!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM
clear empty folders of client computers by linux maryam.sf Linux - Server 5 05-06-2009 11:36 AM
Kubuntu creates empty folders in my home dir bhert Ubuntu 3 06-26-2008 12:59 PM
Samba shares show empty folders Venefyxatu Linux - Wireless Networking 8 06-18-2008 01:50 AM
pkgtool and empty folders jstef Slackware 2 02-04-2003 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration