Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!asuvax!noao!ncar!bierstadt.scd.ucar.edu!sog From: sog@bierstadt.scd.ucar.edu (Steve Gombosi) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <10850@ncar.ucar.edu> Date: 31 Mar 91 02:17:58 GMT References: <1991Mar30.040400.13893@ncsu.edu> <1991Mar30.225406.20493@dg-rtp.dg.com> Sender: news@ncar.ucar.edu Organization: Scientific Computing Division/NCAR, Boulder, CO Lines: 15 Wouldn't it be easier to pipe the output of "ls -la" through "wc -l" and test for the output being equal to two? Since an empty directory contains only "." and "..", and "ls -la" (at least on my system) provides a "Totals" line, the output looks like this: %ls -la empty_directory total 2 drwxr-xr-x 2 sog 512 Mar 30 19:07 . drwxr-xr-x 11 sog 1024 Mar 30 19:10 .. %ls -la empty_directory|wc -l 3 So, if `ls -la directory_name|wc -l` != 3, the directory has something in it. Of course, if it's less than three, something is REALLY screwed up...