Ankur Agarwal
Ankur Agarwal

Reputation: 24768

Using find with -L option

I have this:

mylink -> myfile

When I do:

find -L . -name 'mylink'

I get:

./mylink

I don't understand why this is so, given this from the man page:

-L : Follow symbolic links. When find examines or prints information about files, the information used shall be taken from the properties of the file to which the link points, not from the link itself (unless it is a bro- ken symbolic link or find is unable to examine the file to which the link points).

Based on the above I was expecting the following behavior for my example case: find starts the search. It encounters mylink. Since -L is in effect it dereferences it and gets the name of the pointed to file 'myfile'. The file name does not match the pattern 'mylink' and nothing is reported. Whats happening?

Upvotes: 1

Views: 5995

Answers (2)

ephemient
ephemient

Reputation: 204886

The name is not a property of the file, it's a property of the directory containing it.

If you want to match the contents of a symlink, use -lname.

Upvotes: 1

sehe
sehe

Reputation: 393487

The 'following of links' applies when there is a link to a directory.

A link to a file is just a file itself, to find. Without -L a link to a directory is also just a file.

Only when -L is added, will find recurse into the linked-to directory

Upvotes: 1

Related Questions