<<< Date Index >>>     <<< Thread Index >>>

Re: Reliable/safe way of removing empty maildirs?



On Fri, Dec 07, 2007 at 12:18:03PM +0000, Chris G wrote:
> On Thu, Dec 06, 2007 at 09:05:32PM -0700, Michael Endsley wrote:
> > 
> > On Thu, Dec 06, 2007 at 10:28:26PM +0000, Chris G wrote:
> > > On Thu, Dec 06, 2007 at 09:15:10PM +0000, A Darren Dunham wrote:
> > > > > >> chmod a-w dir/new
> > > > > >> if [ `find dir -type f` ] ; then
> > > > > >
> > > > > > You have to do something like this instead:
> > > > [snip other responses]
> > > > 
> > > > Perhaps I've misunderstood the reason for doing this, but I would just
> > > > ask find to do a rmdir, and let it fail if the directory isn't empty.
> > > > 
> > > > find dir -depth -type d -exec rmdir {} \;
> > > > 
> > > > If 'dir' is still around when that finishes, it's probably because
> > > > there's a file in there now.  In the meantime, it's removed all empty
> > > > subtrees.
> > > > 
> > > ... and left an *awful* mess, a maildir mailbox is a directory with
> > > *three* sub-directories in it, you need to check that all three are
> > > empty before removing them.
> > > 
> > I needed to empty some subdirectories and this is what I did:
> > 
> > du test
> > 4       test/cur
> > 4       test/tmp
> > 4       test/new
> > 16      test
> > 
> > Nothing in the test directory, so I deleted it.
> > 
> Er, and?  I want a command which safely deletes empty maildirs without
> me having to inspect them myself.
> 
> -- 
> Chris Green

Ok, sorry, I missed (or forgot) the original question.