LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Search this Thread
Old 09-15-2005, 11:25 AM   #1
Iriel
Member
 
Registered: Sep 2003
Location: Stow, OH USA
Distribution: Fedora Core 4, Knoppix, openSUSE 10
Posts: 44

Rep: Reputation: 15
finding empty directories with bash


At work, we hired a consultant to help us with our shopping cart software (because the tmp files were never getting cleaned out). His solution was handing us a shell script that would do it for us. The only problem is that it's not working on Solaris 9. I think Solaris 9 doesn't support the -empty option, but I'm not sure. Could anyone help me fix this script?

Code:
/usr/bin/bash
/usr/local/somedirectory/bin/expireall -r
rm -rf /usr/serverdirectory/tmp/addr_ctr/*
find /usr/serverdirectory/tmp -type f -mtime +2 |xargs rm -f
find /usr/serverdirectory/tmp -type d -empty -depth -mindepth 1 |xargs rmdir
 
Old 09-15-2005, 12:05 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

You are correct, the -empty option is not supported.

I do have a solution, although it's kinda 'dirty'.....

Replace this line:
find /usr/serverdirectory/tmp -type d -empty -depth -mindepth 1 |xargs rmdir

With:
find /usr/serverdirectory/tmp -depth -type d -exec rmdir {} 2>/dev/null \;

It searches for all directories and tries to remove them using rmdir. rmdir will refuse to remove dirs that are not empty. Check to see if there isn't an alias defined that overrides this!!! (man rmdir for details).

The 2>/dev/null is there to get rid of all the error messages rmdir produces on non-empty dirs.

If at all possible, try this on a test box first.

Like I said, not elegant, but it works.
 
Old 09-15-2005, 12:52 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,491

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
A cleaner approach would be to use the find command for which the original script was written, aka gnufind or gfind, which is certainly available for Solaris, at least on blastwave.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to search for and delete empty directories? BrianK Programming 4 06-03-2005 07:24 AM
ProFTPD - deleting non-empty directories? orange400 Linux - Software 1 05-28-2004 03:36 AM
Removing non-empty directories brunnopessoa Linux - Newbie 8 11-13-2003 07:56 PM
how do I remove all empty directories? noisybastard Linux - General 2 08-10-2003 11:47 PM
finding empty directories... PokerFace Linux - General 2 10-16-2002 08:23 AM


All times are GMT -5. The time now is 08:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration