Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!agate!ucbvax!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!warwick!cudcv From: cudcv@warwick.ac.uk (Rob McMahon) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: Date: 5 Apr 91 13:52:07 GMT References: <563@bria> <=-#g4!g@rpi.edu> <572@bria> Sender: news@warwick.ac.uk (Network news) Organization: Computing Services, Warwick University, UK Lines: 27 Nntp-Posting-Host: shark I know this is getting silly, but In article <572@bria> uunet!bria!mike writes: >True enough; I didn't account for hidden files. Okay, then how about this >instead? > > if [ `ls $dir/* $dir/.[!.]* | wc -l` = 0 ] ; then touch ..hidden Oops. Also not all versions of sh have the [!...] construction. I think the only sensible way to do this is [ `ls -a $dir | wc -l` = 2 ]; that should be pretty portable. >And under systems that do have this behaviour, I have seen them list . and .. >along with everything else. You sure ? The ls's I've seen that change behaviour for root list everything but . and .., a la -A. Cheers, Rob -- UUCP: ...!mcsun!ukc!warwick!cudcv PHONE: +44 203 523037 JANET: cudcv@uk.ac.warwick INET: cudcv@warwick.ac.uk Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England