In Linux, what is the best way to find all symbolic links that point to a given file (regardless of whether the symlink is relative or absolute)? I realize this will require scanning the whole filesystem.
This will find all links to
You should read up on what the effects of
Note: While the documentation says it looks for files with the same inode number, it does appear to work across filesystems.
e.g. /home and /tmp are separate filesystems
Note how this is returning /tmp/bar, which is a symlink to /tmp/foo, which is a symlink to ~/testfile. If you only wanted to find direct symlinks to your target file, this wont work.
Perhaps the shortest way would be:
But it's not very efficient.
If you don't have
Also, the above example won't handle file names with spaces in it properly. Here's a better way to do it. Note that