[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: no test(1) for empty directories
From: |
Aharon Robbins |
Subject: |
Re: no test(1) for empty directories |
Date: |
Tue, 07 May 2002 14:46:10 GMT |
In article <address@hidden>,
Paul Jarc <address@hidden> wrote:
>address@hidden (Aharon Robbins) wrote:
>> In article <address@hidden>,
>> Dan Jacobson <address@hidden> wrote:
>>> No neat and clean way to use test(1) to find empty directories. Sure,
>>> got -d and -s, but no special -s especially made for directories.
>>
>> You don't need it. Check for directory and link count of 2.
>
>That tells you whether there are subdirectories, not whether there are
>any files at all.
Good point. I suppose
if rmdir $directory_I_want_to_know_is_empty >/dev/null 2>&1
then
: directory was empty, continue
else
: it is not empty, react as needed
fi
is a sure-fire, if slightly drastic, way to do this. (:-)
Something like this would seem to work too:
if [ `ls -1a $dir | wc -l` = 2 ]
then
directory_is_empty
else
it_is_not
fi
Arnold
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd. address@hidden
P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 928 569 9018
Nof Ayalon Cell Phone: +972 51 297-545
D.N. Shimshon 99785 ISRAEL