[Novalug] grep question

Michael Henry lug-user@drmikehenry.com
Fri May 21 06:40:33 EDT 2010


On 05/20/2010 12:45 PM, James Ewing Cottrell 3rd wrote:
> "grep -r pattern dirs..." is roughly equivalent to
>
> find dirs... -type f | xargs grep pattern or
> find dirs... -type f  -exec grep pattern +
>
> except for the egregious mistake of following symlinks.

I was surprised by this statement, since when I'm interactively
searching down a directory tree, I generally *want* to follow
symlinks.  In my view, the purpose of a symlink to a file is to
make that file appear to be in the containing directory.  I'm
pleased that other tools follow symlinks transparently (e.g.,
``cat some-symlink``), so I'm wondering why it seems like a
mistake to you.  I do understand and appreciate why ``find``
doesn't follow symlinks, though, since its purpose is to permit
fine-grained selectivity across a tree in the filesystem, and
it's important to differentiate symlinks from hard links in that
case.  But for tools intended to read files, I prefer them to
follow symlinks by default, and I'm curious as to your reasoning
to consider that behavior an egregious mistake.

Michael Henry




More information about the Novalug mailing list