tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkgsrc littering the home directory

On Tue, 05 Feb 2008 12:42:23 +0700
Robert Elz <kre%munnari.OZ.AU@localhost> wrote:

>     Date:        Tue, 05 Feb 2008 03:32:57 +0100
>     From:        Roland Illig <>
>     Message-ID:  <>
>   | I think checking that the output of "ls -A" is empty is more portable.
> When did -A get to be a truly portable ls flag?   I have no idea if
> it is posix required or not, but it is certainly a "recent" edition
> to ls (by at least wasn't there in 5th, 6tth, or 7th edition unix,
> wasn't there in 3bsd 4bsd to at least 4.2 (not sure about 4.3, but
> probably not there either)).
> If you want truly portable you'd need
>       ls -a | sed -e '/^\.$/d' -e '/^\.\.$/d' -e 3q
> and test the out from that for empty - that at least goes back
> to the introduction of sed (7th edn).   This has the advantage
> that we don't really need the directory listing, and if the
> diretory is big, all we really nead is to know something is
> there, the "3q" sed expression will abort the ls fairly
> quickly, and avoid too much data through the pipe, or into
> the shell (just testing "ls -A" for empty, on a huge
> directory, makes the shell collect perhaps megabytes of
> data, for the sole purpose of testing that there's more
> than 0 bytes...)
> If you want portability to even earlier than that then
>       ls -a | wc -l
> and test the output of that for > 2 (test `...` -gt 2).  That should
> go back further than anyone cares (and still work everywhere, at
> least everywhere that has a test command) but shunts the entire
> directory listing through the pipe, always.
> kre
> ps: I agree using test -s on a directory is not the right way,
> in many implementations that is guaranteed true (size of a
> directory is always > 0 bytes.)

Thanks for the input. ls -A seems bad according to SUSv3.
This is the solution I'll go with (large number of files are not
ls -a foo | \
awk '{if (!($0=="." || $0=="..")) cnt++} END {print cnt?1:0}'

Home | Main Index | Thread Index | Old Index