Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!pacbell!ptsfa!dmturne From: dmturne@PacBell.COM (Dave Turner) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <6090@ptsfa.PacBell.COM> Date: 2 Apr 91 17:19:53 GMT References: <1991Mar30.040400.13893@ncsu.edu> <563@bria> <=-#g4!g@rpi.edu> Reply-To: dmturne@PacBell.COM (Dave Turner) Organization: Pacific * Bell, San Ramon, CA Lines: 23 In article <=-#g4!g@rpi.edu> fitz@mml0.meche.rpi.edu (Brian Fitzgerald) writes: >>>Michael Harris writes: >>>>When I am running a shell script, how can I tell when a directory is empty? >> >> if [ `ls $dir | wc -l` = 0 ] ; then >> Use the form of ls that gives all entries in a directory including . and .. . Check for a count of two. For System V and the Bourne shell if [ `ls -a $dir | wc -l` -eq 2 ] then echo empty else echo not empty fi -- Dave Turner 415/823-2001 {att,bellcore,sun,ames,decwrl}!pacbell!dmturne