Lets say, when I do ls -li inside a directory, I get this:

12353538 -rw-r--r-- 6 me me 1650 2013-01-10 16:33 fun.txt

As the output shows, the file fun.txt has 6 hard links; and the inode number is 12353538.

Given the case, how do I find all the hard links for the file i.e. files with the same inode number?

find /mount/point -samefile /mount/point/your/file
  • 3
    @TheoneManis I just noticed that the other parts of the find call are not necessary. find is clever enough to use them implicitely. Usually you have to give find a search path and have to tell it that is shall not leave these file systems (via symlinks or mount points). But when looking for hard links it's clear on which file system to search. – Hauke Laging Apr 24 '13 at 13:51
  • 6
    Hauke, that depends on the version of find you're using. The GNU version might do that, but the BSD one does not, and this will not work as-is on Mac. – Alan Shutko Apr 24 '13 at 19:36
  • 3
    You may want to add -xdev to avoid descending into directories in other filesystems, otherwise you might find another file with the same inode number located in another filesystem. – mmoya Nov 17 '13 at 17:46
  • The near-equivalent to -samefile on HP-UX is -linkedto (though it is slightly different: a search path must still be specified, for example). – Nick Aug 27 '15 at 19:37
  • 3
    Note that if you are not in the root of your mount point, find will explore only subfolders of the current folder. So you should really say something like find /mount/point -samefile /mount/point/your/file – Calimo Apr 6 '17 at 13:30

If you already have the inode number you can use find's -inum option:

find -inum 12353538
  • 11
    Don't forget to cd to the root of the file system, or specify it as a path to find, like find /mount/point -inum 12353538. Otherwise find will look only in below the current folder. – Calimo Apr 6 '17 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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