testing if a directory is empty (OOOPS!)
Bruce R Larson
ires at kaspar.ires.com
Fri Apr 19 10:32:55 AEST 1991
>In article < ... > pauld at cs.washington.edu (Paul Barton-Davis) writes:
>| So it needs to be:
>|
>| [ "`cd $1 ; echo .??* *`" = ".??* *" ]
In article < ... > meissner at osf.org (Michael Meissner) writes:
> ... the following should work:
>
> [ "`cd $1; echo .[^.] .??* *`" = ".[^.] .??* *" ]
Here's how I've checked for empty dirs
#!/bin/sh
if [ "`ls -la $1 | wc -l`" -eq 3 ]; then echo empty; fi
NOTE: every "ls -l" I've used lists the "total" number of
entries on its first line of output, hence the "3".
Bruce
--
Bruce R. Larson
Integral Resources, Milton MA
Internet: blarson at ires.com
Uucp: ..!{world|uunet}!ires.com!blarson
More information about the Comp.unix.questions
mailing list