symbolic link: find all files that link to this file

lukmac picture lukmac · May 31, 2011 · Viewed 80k times · Source

Hallo all, I need to do this in linux:

  • Given: file name 'foo.txt'
  • Find: all files that are symbolic links to 'foo.txt'

How to do it? Thanks!

Answer

DigitalRoss picture DigitalRoss · May 31, 2011

It depends, if you are trying to find links to a specific file that is called foo.txt, then this is the only good way:

find -L / -samefile path/to/foo.txt

On the other hand, if you are just trying to find links to any file that happens to be named foo.txt, then something like

find / -lname foo.txt

or

find . -lname \*foo.txt # ignore leading pathname components