find: Symbolic Links

1 
1 2.2.1 Symbolic Links
1 --------------------
1 
1 Symbolic links are names that reference other files.  GNU 'find' will
1 handle symbolic links in one of two ways; firstly, it can dereference
1 the links for you - this means that if it comes across a symbolic link,
1 it examines the file that the link points to, in order to see if it
1 matches the criteria you have specified.  Secondly, it can check the
1 link itself in case you might be looking for the actual link.  If the
1 file that the symbolic link points to is also within the directory
1 hierarchy you are searching with the 'find' command, you may not see a
1 great deal of difference between these two alternatives.
1 
1    By default, 'find' examines symbolic links themselves when it finds
1 them (and, if it later comes across the linked-to file, it will examine
1 that, too).  If you would prefer 'find' to dereference the links and
1 examine the file that each link points to, specify the '-L' option to
1 'find'.  You can explicitly specify the default behaviour by using the
1 '-P' option.  The '-H' option is a half-way-between option which ensures
1 that any symbolic links listed on the command line are dereferenced, but
1 other symbolic links are not.
1 
1    Symbolic links are different from "hard links" in the sense that you
1 need permission to search the directories in the linked-to file name to
1 dereference the link.  This can mean that even if you specify the '-L'
1 option, 'find' may not be able to determine the properties of the file
1 that the link points to (because you don't have sufficient permission).
1 In this situation, 'find' uses the properties of the link itself.  This
1 also occurs if a symbolic link exists but points to a file that is
1 missing.
1 
1    The options controlling the behaviour of 'find' with respect to links
1 are as follows:
1 
1 '-P'
1      'find' does not dereference symbolic links at all.  This is the
1      default behaviour.  This option must be specified before any of the
1      file names on the command line.
1 '-H'
1      'find' does not dereference symbolic links (except in the case of
1      file names on the command line, which are dereferenced).  If a
1      symbolic link cannot be dereferenced, the information for the
1      symbolic link itself is used.  This option must be specified before
1      any of the file names on the command line.
1 '-L'
1      'find' dereferences symbolic links where possible, and where this
1      is not possible it uses the properties of the symbolic link itself.
1      This option must be specified before any of the file names on the
1      command line.  Use of this option also implies the same behaviour
1      as the '-noleaf' option.  If you later use the '-H' or '-P'
1      options, this does not turn off '-noleaf'.
1 
1      Actions that can cause symbolic links to become broken while 'find'
1      is executing (for example '-delete') can give rise to confusing
1      behaviour.  Take for example the command line 'find -L . -type d
1      -delete'.  This will delete empty directories.  If a subtree
1      includes only directories and symbolic links to directoires, this
1      command may still not successfully delete it, since deletion of the
1      target of the symbolic link will cause the symbolic link to become
1      broken and '-type d' is false for broken symbolic links.
1 
1 '-follow'
1      This option forms part of the "expression" and must be specified
1      after the file names, but it is otherwise equivalent to '-L'.  The
1      '-follow' option affects only those tests which appear after it on
1      the command line.  This option is deprecated.  Where possible, you
1      should use '-L' instead.
1 
1    The following differences in behaviour occur when the '-L' option is
1 used:
1 
1    * 'find' follows symbolic links to directories when searching
1      directory trees.
1    * '-lname' and '-ilname' always return false (unless they happen to
1      match broken symbolic links).
1    * '-type' reports the types of the files that symbolic links point
1      to.  This means that in combination with '-L', '-type l' will be
1      true only for broken symbolic links.  To check for symbolic links
1      when '-L' has been specified, use '-xtype l'.
1    * Implies '-noleaf' (⇒Directories).
1 
1    If the '-L' option or the '-H' option is used, the file names used as
1 arguments to '-newer', '-anewer', and '-cnewer' are dereferenced and the
1 timestamp from the pointed-to file is used instead (if possible -
1 otherwise the timestamp from the symbolic link is used).
1 
1  -- Test: -lname pattern
1  -- Test: -ilname pattern
1      True if the file is a symbolic link whose contents match shell
1      pattern PATTERN.  For '-ilname', the match is case-insensitive.
1      ⇒Shell Pattern Matching, for details about the PATTERN
1      argument.  If the '-L' option is in effect, this test will always
1      return false for symbolic links unless they are broken.  So, to
1      list any symbolic links to 'sysdep.c' in the current directory and
1      its subdirectories, you can do:
1 
1           find . -lname '*sysdep.c'
1