Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I use the inode number to locate all hardlinks to the file "file.txt" in my home directory?

share|improve this question

1 Answer 1

To find all files in your home directory with inode number N, use either

find ~ -maxdepth 1 -inum N

(home directory only) or

find ~ -xdev -inum N

(includes subdirectories).

The switch -xdev prevents finding files with the same inode number on different file systems, since they're not the hardlinks we're looking for.

To find all hardlinks to file.txt, you can use

find -inum "$(stat -c %i file.txt)"

with or without the -maxdepth switch.

See:

share|improve this answer
2  
I'd add -xdev, for completeness in the general case. By definition, hard links will be on the same file system. (Though in this particular case, home dirs are very unlikely to span filesystems). –  Rich Homolka Mar 27 '13 at 14:25

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.