I have a file system where one or more symlinks exist to a file. Is there a way to go thru each file and determine where all the symlinks that point to it on the file system are?

OS is Ubuntu 9.10 Linux

link|improve this question

73% accept rate
Operating system? – DaveParillo Apr 21 '10 at 3:55
linux - ubuntu 9.10 to be exact – Roy Rico Apr 22 '10 at 15:41
feedback

1 Answer

up vote 2 down vote accepted

You can use good old find with the -lname switch:

find / -lname '/path/to/linked/file' 2> /dev/null

For a more intricate approach, you can use the inode number of the file (retrieve from ls -i <file>):

find / -follow -inum 123456 2> /dev/null
link|improve this answer
this has the limitation that it only matches a symlink with that exact filename (or pattern). it wouldn't catch a symlink to a symlink to that file. (so if symB points to fileA and symC points to symB, and you run this command looking for fileA, it'll find symB but not symC.) – quack quixote Apr 21 '10 at 4:05
True, but I'm just following the criteria he's given us. – John T Apr 21 '10 at 4:07
just sayin'. nice addition tho. :) – quack quixote Apr 21 '10 at 4:19
feedback

Your Answer

 
or
required, but never shown

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