[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Checking if directory is empty in postrm



Sorry to provide such a late reply, I was off-list for a couple of
days.  However, I've reviewed the answers provided so far, and I like
mine better.  :-)

First, the easiest and most obvious way to check if a directory is empty
is to rm it.  If that succeeds, the directory was empty.  Of course,
sometimes you don't want to remove it.  In that case, try this:

if [ "$(echo * .*)" = "* . .." ] ; then echo empty dir; fi

No overhead for calling external programs, except echo which is a shell
builtin.  No calls to ls, wc, or grep.  Simple and fast, if a little bit
inobvious.
-- 
Chris Waters   xtifr@dsp.net | I have a truly elegant proof of the
or   cwaters@systems.DHL.COM | above, but it is too long to fit into
http://www.dsp.net/xtifr     | this .signature file.


Reply to: