How to find all symbolic links to a given file/directory?
Use find /dir -lname /link/target
. It searches link contents with shell pattern; e.g. you can use * and ? wildcards in target specification.
One drawback of this method is that it searches contents of links, not their expanded paths, so if you need to find relative links to absolute paths (if e.g. there are more than one file with same name) you need a more complicated script.
Also you can use other apporoach: find -L /dir -samefile /link/target
. This causes find
to dereference symlinks and after check the dereferenced path that is expanded by OS to be same as provided, so both relative and absolute links will be handled by Linux. This solves problem of previous method.