Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted
find -samefile /mount/point/your/file
share|improve this answer
2  
@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
    
Got it. Thanks for the explanation. :) –  its_me Apr 24 '13 at 13:54
4  
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
    
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
add comment

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

find -inum 12353538
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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