this seems a very good test, but the system says "[: too may arguments"


-----Original Message-----
From: Anand Buddhdev [mailto:[EMAIL PROTECTED]
Sent: 07 March 2003 09:55
To: [EMAIL PROTECTED]
Subject: Re: test empty dir


On Fri, Mar 07, 2003 at 08:52:56AM -0000, Zhi Cheng Wang wrote:

> dear gurus
> 
> 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

> but I think it is ugly, any pretty way? ...

-- 
Anand Buddhdev
http://anand.org



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list
 
--------------------------------------------------------

 
This email is confidential and intended solely for the use of the person(s) ('the 
intended recipient') to whom it was addressed. Any views or opinions presented are 
solely those of the author and do not necessarily represent those of the Paterson 
Institute for Cancer Research or the Christie Hospital NHS Trust. It may contain 
information that is privileged & confidential within the meaning of applicable law. 
Accordingly any dissemination, distribution, copying, or other use of this message, or 
any of its contents, by any person other than the intended recipient may constitute a 
breach of civil or criminal law and is strictly prohibited. If you are NOT the 
intended recipient please contact the sender and dispose of this e-mail as soon as 
possible.
 



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to