Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!news.cs.indiana.edu!news.nd.edu!mentor.cc.purdue.edu!sage.cc.purdue.edu!asg From: asg@sage.cc.purdue.edu (Bruce Varney) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <9424@mentor.cc.purdue.edu> Date: 3 Apr 91 16:31:06 GMT References: <1991Mar30.040400.13893@ncsu.edu> <1991Mar30.225406.20493@dg-rtp.dg.com> <1991Apr3.142150.4445@athena.mit.edu> Sender: news@mentor.cc.purdue.edu Reply-To: asg@sage.cc.purdue.edu (Bruce Varney) Organization: Purdue University Lines: 53 In article <1991Apr3.142150.4445@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: }In article <1991Mar30.225406.20493@dg-rtp.dg.com>, hunt@dg-rtp.rtp.dg.com (Greg Hunt) writes: }|> Telling whether a directory is empty from a script should be possible }|> by looking at the size of the directory itself. If the directory size }|> is zero, then the directory is empty. Otherwise, it contains some }|> files. You should check this out on your system to make sure it holds }|> true for the flavor of UNIX that you're using. } } Um, I can't imagine this being true for *any* remotely normal flavor of Unix. } You're right Jon [ :-( gasp!, did I really say that? ] But why are you all making this so hard????? Its easy. do this: ---isempty--- #!/bin/sh dir=$1 num1=`ls -aF $dir | grep -v "/$" | wc -l` num2=`expr \`ls -lad $dir | cut -c12-13\` - 2 ` num=`expr $num1 + $num2` if [ $num = "0" ] then echo The directory is empty else echo The directory is not empty fi ---isempty--- then just do isempty directory_in_question and it will tell you if the dir is empty or not }-- }Jonathan Kamens USnail: ^^^^^^ Get the UShammer!!! Bruce --------- sar.casm \'sa:r-.kaz-*m\ \sa:r-'kas-tik\ \-ti-k(*-)le-\ n [F sarcasme, fr. LL sarcasmos, fr. Gk sarkasmos, fr. sarkazein to tear flesh, bite the lips in rage, sneer, fr. sark-, sarx flesh; akin to Av thwar*s to cut] 1: a cutting, hostile, or contemptuous remark : GIBE 2: the use of caustic or ironic language - sar.cas.tic aj ### ## Courtesy of Bruce Varney ### # aka -> The Grand Master # asg@sage.cc.purdue.edu ### ##### # PUCC ### # ;-) # # ;'> # ##