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

Brett Parker iDunno at sommitrealweird.co.uk
Wed Feb 21 12:45:32 GMT 2007


On Wed, Feb 21, 2007 at 12:41:41PM +0000, MJ Ray wrote:
> On Wed, Feb 21, 2007 at 11:42:10AM +0000, Eur Ing Chris Green wrote:
> > What's the simplest (and/or most concise) way to check for an empty
> > directory?
> 
> Is it
> [ -d $dirname ] && [ $dirname/* == "$dirname/*" ]
> in Bourne shell?

ENOCIGAR

brettp at fudge:~$ if [ -d empty ] && [ empty/* == "empty/*" ]; then echo
empty; fi
empty
brettp at fudge:~$ if [ -d .xmms ] && [ .xmms/* == ".xmms/*" ]; then echo
empty; fi
bash: [: too many arguments
brettp at fudge:~$ 

Cheers,
-- 
Brett Parker



More information about the main mailing list