1

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand, how is name not a property of the file?
A directory is made up of directory entries which map names to inodes, which are the files themselves. An inode has metadata (such as size, time, and permissions), but no intrinsic name. In fact, a file (inode) may have many names — see hardlinks.
1

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

2 Comments

-L also affects the meaning of stat-related tests, such as -uid.
@ephemient: good point, I hadn't checked whether find uses lstat instead of stat with -L

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.