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

Re: Reliable/safe way of removing empty maildirs?



On 06Dec2007 21:15, A Darren Dunham <ddunham@xxxxxxxx> 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.

Yeah, but without even invoking find:

  rmdir dir/new dir/tmp dir/cur dir \
  || mkdir -p dir/new dir/tmp dir/cur

Robust, safe, trivial.

People always seem to forget that rmdir is perfectly safe, in that it
won't remove empty directories.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

Thousands at his bidding speed,
And post o'er land and ocean without rest       - Milton