[ALUG] Re: How to check a directory is empty (probably in bash)?

Eur Ing Chris Green cl at isbd.net
Wed Feb 21 13:03:10 GMT 2007


On Wed, Feb 21, 2007 at 12:49:13PM +0000, Paul wrote:
> On Wednesday 21 February 2007 11:42, Eur Ing Chris Green wrote:
> > What's the simplest (and/or most concise) way to check for an empty
> > directory?
> 
> if test -z `ls foo` ; then wibble ; fi
> 
>  Or
> 
> if [ -z `ls foo` ] ; then wibble ; fi
> 
That's neat!  It's not actually perfect because hidden files in the
directory will break it, but it's perfect for my application as I
don't care about hidden files.

> There's probably other ways....
> 
No doubt, but the above will do very well, thanks (and for all the
other ideas).

-- 
Chris Green



More information about the main mailing list