Search code examples
clinuxhardlink

Print hard links on file


I have to write out all hard links on file in C. I have no idea how to do that. One possibility is also to call bash command but which command to call?

Given: file name 'foo.txt'

Find: all files that are hard links to 'foo.txt'


Solution

  • Get the inode number of the file (ls -i will give it), then use find root_path_of_the_partition -inum inode_number. Beware to find by inode number on the same partition, as it is possible that two different files have the same inode number, provided that they are on different partitions.