Re: Symlink strangeness

Linus Torvalds (torvalds@transmeta.com)
15 Sep 1998 05:22:28 GMT


In article <Pine.LNX.3.96.980914231858.1650A-100000@air.fast.net>,
Steven N. Hirsch <shirsch@adelphia.net> wrote:
>
>This is a strange one.

Not really. I'd say it was strange if you hadn't seen this before..

> With kernel 2.1.122-pre2, I have this situation:
>
>total 669
>drwxr-xr-x 23 hirsch system 36864 Sep 14 18:23 .
>drwxr-xr-x 3 root root 0 Sep 12 17:55 ..
>lrwxrwxrwx 1 hirsch system 13 Sep 12 14:29 linux -> linux-2.1.122
>drwxr-xr-x 15 hirsch system 1024 Sep 13 13:25 linux-2.1.122
>
>Doing this gets me zero hits:
>
>(hirsch@air) ~ : find /usr/src/linux -name "*.h" -print

This is correct. "find" will not follow symlinks, so as far as find is
concerned, you're asking it to find a file with the name '*.h', but
you're only giving it a single file (that happens to be a symlink) to
look at.

It's certainly not new to 2.1.122-pre2.

If you want 'find' to follow the symlink, you can either:

- add a final slash at the end of the name, which will essentially
force the first symlink to be evaluated by virtue of there now being
a final zero-length name at the end of the path.
- use the "-follow" argument to 'find', telling find to follow symlinks
(and be careful about not constructing endless loops ;)

>If I start the find below the root of the source tree, e.g:
>
>find /usr/src/linux/arch ....(etc.)
>
>it works properly.

Because now you're not giving 'find' a symlink, but a real directory
entry to start with (it happens to follow a symlink when getting to the
directory, but the file itself is not one).

>Seems like broken behavior.

No, it's both documented and standard, and makes tons of sense when
considering how 'find' is often used.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/