The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find empty folders without using -empty lasse UNIX for Dummies Questions & Answers 7 01-16-2008 11:30 PM
identify the empty directories mohan705 Shell Programming and Scripting 5 07-07-2007 08:31 AM
Empty directories having different size rahulrathod UNIX for Dummies Questions & Answers 3 01-19-2006 08:53 AM
Help identifying empty directories dboard UNIX for Dummies Questions & Answers 2 11-09-2005 12:07 PM
searching for list of empty directories man80 Shell Programming and Scripting 4 10-15-2004 01:00 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-17-2004
Registered User
 

Join Date: Feb 2004
Location: Belgium
Posts: 2
scanning empty directories

Hi,

I want to produce a text file representing a list of empty directories on a unix system starting from a specified directory.
I hope I explained well my problem.

Thanks in advance.
Reply With Quote
Forum Sponsor
  #2  
Old 02-17-2004
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
If you're just looking to delete empty directories, you can use this:
Code:
find . -exec rmdir {} \;
but use it with caution! It'll go ahead and remove all empty directories in the specified path, skipping regular files and directories that contain other files.

As far as just creating a list, I'm not sure...
Reply With Quote
  #3  
Old 02-17-2004
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Quote:
Originally posted by oombera
If you're just looking to delete empty directories, you can use this:
Code:
find . -exec rmdir {} \;
but use it with caution! It'll go ahead and remove all empty directories in the specified path, skipping regular files and directories that contain other files.

As far as just creating a list, I'm not sure...

use -print after the semicolon so you can see a list of the directories you just deleted.
Reply With Quote
  #4  
Old 02-17-2004
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Figured out a better way.
Code:
find . -type d -links 2 -exec echo '{}' >> somefile \;
Reply With Quote
  #5  
Old 02-18-2004
Registered User
 

Join Date: Feb 2004
Location: Belgium
Posts: 2
Hi Oombera,

thanks for your suggestion.
However, it doesn't seem to work 100%. it returns all the directories, empty or not. I must say, I tried your command on a Iseries (AS400) UNIX shell.
I will try it on a real UNIX (sun solaris) machine.
I'll keep you in touch.

PS. with you it worked well?

Thanks
Reply With Quote
  #6  
Old 02-18-2004
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Quote:
Originally posted by N065956BM
PS. with you it worked well?
Yea - for me it returned only the empty directories. Let me know if it works for you on the solaris machine...
Reply With Quote
  #7  
Old 02-18-2004
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
as400 is more mainframe then it is a unix.

as400 commands are really weird, iv only had a brief experiance with as400 when i used to tool around on it when i worked for a school.

it wouldnt surpise me that the find command didnt perform as expected on an as400.

oombera your orig command would work. i am haveing a hard time understanding what the use of the -links 2 is for in this instance. unless a file has 2 links to it it will not be posted.

find . -type d -exec rmdir {} \; -print

this is what you would be looking for.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0