Should "ls -R" traverse symlinks?

Guy Harris guy at auspex.auspex.com
Fri May 12 19:05:42 AEST 1989


 >On a Sun3 running SunOS 3.5.1, "ls -R" does not traverse the "netnews"
 >symlink.
 >
 >On a Pyramid running OSx 4.[04], "ls -R" *does* traverse the symlink.
 >
 >Which is right?

Assuming it's not a rhetorical question, the answer is probably "it
depends".  It depends on what you're using the "ls -R" for; there are
probably cases where you want it to follow the link, and cases where you
don't.  I've probably run across both, or at least the moral equivalent
of both, using "find"; given a choice of only one, I'd *probably* go for
"don't follow", given that people have gotten rude surprises when
symlinks *were* followed by things like the shell (e.g., "rm -f */*",
only one of the first "*"s is a symlink to some directory that you
*really* didn't want to ream out).  "ls" isn't likely to be as rude as
"rm", but still... (and, of course, you *could* be using the "ls" to
generate a list of files to be monkeyed with somehow).

So what you want, presumably, is a "follow/don't-follow" flag.  The "-L"
flag to "ls" is such a flag; I tried an example like yours on a SunOS
4.0 system, and "ls -R" didn't follow the link, but "ls -RL" did.  Of
course, "ls -RL" will follow *every* link it runs across. 



More information about the Comp.unix.wizards mailing list