2

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

1 Answer 1

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:

1
  • 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). Commented Mar 27, 2013 at 14:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .