Listing All Linked Files

0

I can't seem to find a way to do this, so maybe it's not actually possible, but I was wondering if there was a way to list all files that link to a file.

For example.

touch a
ln a b
ln a c

I want to find out what files link to a (not symlinks, mind you), assuming that this is more complicated (they are spread around to different directories).

I kind of understand about the filesystem storing links in one area and data in another, so I understand it probably takes more work to find a link from a file location than the other way around.

If I missed another question asking the same thing, let me know.

bradlis7

Posted 2010-01-21T21:15:23.103

Reputation: 273

Answers

3

Try find / -samefile /file/to/compare.

There were a similar question: Finding all symbolic and hard links to a file on UNIX

whitequark

Posted 2010-01-21T21:15:23.103

Reputation: 14 146

Ah, ok. I guess I just wasn't searching for the correct thing. Thanks! – bradlis7 – 2010-01-21T22:50:09.657

This only works with GNU Find. – Ollie Saunders – 2010-06-07T13:00:29.167

I found no convenient options to do this in BSD Find, but you could try getting an inode number with ls -i and then doing find /mountpoint -x -inum $INODE. Inode represents contents of the file and not the filename. – whitequark – 2010-06-07T14:37:51.050