[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug with ls
From: |
Eric Blake |
Subject: |
Re: bug with ls |
Date: |
Tue, 10 Feb 2009 20:51:48 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Jason Temple on 2/10/2009 3:16 PM:
> Greetings,
> I was trying to recursively list all the directories, *only the
> directories* on a linux system (debian, 8.10) and ran into a bug.
> ls -d /* ---- lists all directories in / (one level deep, expected)
> ls -dR /* ---- lists all directories in / (one level deep, no
> recursive directory traversal)
Thanks for the report. However, POSIX states:
"-R
Recursively list subdirectories encountered."
"-d
...Do not treat directories differently than other types of files. The
use of -d with -R produces unspecified results."
http://www.opengroup.org/onlinepubs/9699919799/utilities/ls.html
The traditional implementation is that since -d does not treat directories
differently from any other files encountered during readdir() traversal,
that there are no subdirectories encountered, and thus -R does nothing.
>
> I can use
>
> find / type d ----- which gives me the desired results, but I feel that
> ls -dR, from its man page should work in this capacity.
You are correct that using find is the only portable way to do what you
want. POSIX leaves us leeway to change ls behavior to match your desires,
but it would take someone willing to write a patch. Also, it would be
nice if you could find another implementation that does what you want (I
just checked OpenBSD and Solaris 10, both of which behave like coreutils);
it's harder to justify a patch that makes us behave differently than other
implementations. Meanwhile, any patch to the documentation to make it
more obvious that -R is a no-op in the presence of -d is both simpler to
write and also more likely to be applied immediately.
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkmSS1MACgkQ84KuGfSFAYBYEgCfdsYuCFRVFxY6/Dg0tccVsfmh
JNQAoNDJswHSnx81VwzNiBfPWs4uAM17
=tBtX
-----END PGP SIGNATURE-----
- bug with ls, Jason Temple, 2009/02/10
- Re: bug with ls,
Eric Blake <=