Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.


  Search this Thread
Old 09-15-2005, 12:25 PM   #1
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?

/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, 01:05 PM   #2
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381

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

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, 01:52 PM   #3
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,571

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.


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 08:24 AM
ProFTPD - deleting non-empty directories? orange400 Linux - Software 1 05-28-2004 04:36 AM
Removing non-empty directories brunnopessoa Linux - Newbie 8 11-13-2003 08:56 PM
how do I remove all empty directories? noisybastard Linux - General 2 08-11-2003 12:47 AM
finding empty directories... PokerFace Linux - General 2 10-16-2002 09:23 AM

All times are GMT -5. The time now is 01:10 PM.

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