Newsgroups: comp.unix.questions Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!fitz From: fitz@mml0.meche.rpi.edu (Brian Fitzgerald) Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <=-#g4!g@rpi.edu> Nntp-Posting-Host: mml0.meche.rpi.edu Organization: Rensselaer Polytechnic Institute, Troy NY References: <1991Mar30.040400.13893@ncsu.edu> <563@bria> Date: 1 Apr 91 06:03:52 GMT Lines: 34 >>Michael Harris writes: >>>When I am running a shell script, how can I tell when a directory is empty? I replied: >>Try: >> >> if [ ! "`ls -A $name`" ] ; then Michael Stefanik writes: >$ ls -A /tmp >ls: illegal option -- A >usage: ls -RadCxmnlogrtucpFbqisfLk [files] > >How about this instead? > > if [ `ls $dir | wc -l` = 0 ] ; then > >I think that this would work rather consistently, regardless of the >pecularities of /bin/ls. %-( [22] mml0 fitz /tmp% mkdir foo [23] mml0 fitz /tmp% ls foo [24] mml0 fitz /tmp% touch foo/.hidden [25] mml0 fitz /tmp% ls foo [26] mml0 fitz /tmp% #-) [30] mml0# cd /tmp /tmp [31] mml0# ls foo .hidden