Symbolic links are names that reference other files. GNU find
will handle symbolic links in one of two ways; firstly, it can
dereference the links for you - this means that if it comes across a
symbolic link, it examines the file that the link points to, in order
to see if it matches the criteria you have specified. Secondly, it
can check the link itself in case you might be looking for the actual
link. If the file that the symbolic link points to is also within the
directory hierarchy you are searching with the find
command,
you may not see a great deal of difference between these two
alternatives.
By default, find
examines symbolic links themselves when it
finds them (and, if it later comes across the linked-to file, it will
examine that, too). If you would prefer find
to dereference
the links and examine the file that each link points to, specify the
-L option to find
. You can explicitly specify the
default behaviour by using the -P option. The -H
option is a half-way-between option which ensures that any symbolic
links listed on the command line are dereferenced, but other symbolic
links are not.
Symbolic links are different to “hard links” in the sense that you need permissions upon the linked-to file in order to be able to dereference the link. This can mean that even if you specify the -L option, find may not be able to determine the properties of the file that the link points to (because you don't have sufficient permissions). In this situation, find uses the properties of the link itself. This also occurs if a symbolic link exists but points to a file that is missing.
The options controlling the behaviour of find
with respect to
links are as follows :-
find
does not dereference symbolic links at all. This is the
default behaviour. This option must be specified before any of the
path names on the command line.
find
does not dereference symbolic links (except in the case of
file names on the command line, which are dereferenced). If a
symbolic link cannot be dereferenced, the information for the symbolic
link itself is used. This option must be specified before any of the
path names on the command line.
find
dereferences symbolic links where possible, and where this
is not possible it uses the properties of the symbolic link itself.
This option must be specified before any of the path names on the
command line. Use of this option also implies the same behaviour as
the -noleaf option. If you later use the -H or
-P options, this does not turn off -noleaf.
The following differences in behavior occur when the -L option is used:
find
follows symbolic links to directories when searching
directory trees.
If the -L option or the -H option is used, the filenames used as arguments to -newer, -anewer, and -cnewer are dereferenced and the timestamp from the pointed-to file is used instead (if possible – otherwise the timestamp from the symbolic link is used).
True if the file is a symbolic link whose contents match shell pattern pattern. For -ilname, the match is case-insensitive. See Shell Pattern Matching, for details about the pattern argument. If the -L option is in effect, this test will always fail for symbolic links unless they are broken. So, to list any symbolic links to sysdep.c in the current directory and its subdirectories, you can do:
find . -lname '*sysdep.c'