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

Reply via email to