33

This question already has an answer here:

How can we find all hard links to a given file? I.e., find all other hard links to the same file, given a hard link?

Does filesystem keep track of the hard links to a file?

The inode of a file only stores the number of hard links to the file, but not the hard links, right?

marked as duplicate by Mikel, slm May 7 '15 at 4:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

38

If the given file is called /path/to/file and you want to find all hard links to it that exist under the current directory, then use:

find . -samefile /path/to/file 

The above was tested on GNU find. Although -samefile is not POSIX, it is also supported by Mac OSX find and FreeBSD find.

Documentation

From GNU man find:

-samefile name
       File refers to the same inode as name. When -L is in effect, this can include symbolic links.

  • 1
    The result of this query is incomplete for users lacking privileges on the directories that contain the hard links. – Aaron Brick Jan 16 '18 at 6:55
  • 3
    Of course. You're listing entries in directories. You need read access to those directories in order to list them. – reinierpost Jan 30 '18 at 17:01

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