how would i find all locations of symlinks that point to a particular path or file?

2

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

Roy Rico

Posted 2010-04-21T03:31:47.330

Reputation: 4 808

Operating system? – DaveParillo – 2010-04-21T03:55:49.727

linux - ubuntu 9.10 to be exact – Roy Rico – 2010-04-22T15:41:18.720

Answers

3

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

John T

Posted 2010-04-21T03:31:47.330

Reputation: 149 037

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 – 2010-04-21T04:05:06.163

True, but I'm just following the criteria he's given us. – John T – 2010-04-21T04:07:11.790

just sayin'. nice addition tho. :) – quack quixote – 2010-04-21T04:19:43.680