Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can you find all symbolic links to a given file / directory?

This previous question only applies to hardlinks (if I read correctly).

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
awesome, thanks! –  warren Jan 20 '10 at 22:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.