From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,8fef2fe508180e8d X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2000-10-25 23:38:05 PST Path: supernews.google.com!sn-xit-02!supernews.com!bignews.mediaways.net!newscore.gigabell.net!newsfeeds.belnet.be!news.belnet.be!btnet-peer1!btnet-peer0!btnet!dispose.news.demon.net!demon!news.demon.co.uk!demon!pappnase.demon.co.uk!not-for-mail From: "Adam Price" Newsgroups: comp.unix.tru64 Subject: Re: Check for files in a directory Date: Thu, 26 Oct 2000 07:28:21 +0100 Message-ID: <972542253.12957.1.nnrp-03.c2deb51d@news.demon.co.uk> References: NNTP-Posting-Host: pappnase.demon.co.uk X-NNTP-Posting-Host: pappnase.demon.co.uk:194.222.181.29 X-Trace: news.demon.co.uk 972542253 nnrp-03:12957 NO-IDENT pappnase.demon.co.uk:194.222.181.29 X-Complaints-To: abuse@demon.net X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Xref: supernews.google.com comp.unix.tru64:650 "Arthur Dalessandro" wrote in message news:svernidqsb8975@corp.supernews.com... > I've seen the man test pages, which show if a file exists, is there a quick > and dirty way of checking whether a given directory contains any files? I > have a cron job that I want to run, the job should only be run if these temp > files exist in the given directory. Any help would be appreciated. > > You can do something like cd $dir count=$(ls -la | wc -l) and check for a count greater than 2, or you can make use of the fact that rmdir will fail if there are files in the directory. If it succeeds then recreate the dir. Hope this helps Adam PS Try searching comp.unix.shell on deja.com this question has come up recently and I think there were some better answers than the 2 I gave above but I'm not sure.