Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top