Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsl!urban From: urban@cbnewsl.att.com (john.urban) Newsgroups: comp.unix.questions Subject: Re: How do I tell when a directory is empty in a script? Message-ID: <1991Apr3.211052.893@cbnewsl.att.com> Date: 3 Apr 91 21:10:52 GMT References: <1991Mar30.040400.13893@ncsu.edu> <563@bria> Organization: AT&T Bell Laboratories Lines: 24 >In an article, mml0.meche.rpi.edu!fitz (Brian Fitzgerald) writes: >Michael Harris writes: >>When I am running a shell script, how can I tell when a directory is empty? > >Try: > > if [ ! "`ls -A $name`" ] ; then Why not just run rmdir $directory and if it works, then the directory was empty. ie. if [ -d test1 ] then rmdir test1 if [ -d test1 ] then echo Not empty directory test1 else mkdir test1 echo Empty directory test1 fi fi Sincerely, John Urban