[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: test empty dir
- From: Anand Buddhdev <arb anand org>
- To: redhat-list redhat com
- Subject: Re: test empty dir
- Date: Fri Mar 7 08:31:20 2003
On Fri, Mar 07, 2003 at 11:12:07AM -0000, Zhi Cheng Wang wrote:
> this seems a very good test, but the system says "[: too may arguments"
Ouch. Sorry, I forgot the quotes. Thanks to everyone who spotted this
and responded while I was on the bus :)
> > how can i test if a directory is empty? at the moment i use the following method:
> >
> > ls -l /dirname | grep "total 0"
> > if [ $? ] then ....
>
> This is not a good test. "ls -l" will not reveal dot-files.
>
> Use "ls -A" which will list all files, including the dotted ones, but
> excluding '.' and '..'.
>
> if [ -z `ls -A /dirname` ]; then echo "empty"; fi
--
Anand Buddhdev
http://anand.org
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]