3

What is, on Linux, the way to get a list of a file's hardlinks ?

4 Answers 4

3
find /partition_root -samefile /partition_root/file/to/find/hardlinks/of
6

Start by ensuring that the hardlink count from ls is more than 0.

If so, then you can search for them, somewhat painstakingly:

find <path> -type f -samefile <source>

This finds all files in a given path and compares the inode number of your source file against that of the found file(s). Hardlinks share the same inode. So if they match you have yourself a hardlink.

3

There may be an easier/quicker method but

stat file

which gives something similar to

  File: `file'
  Size: 14              Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 4227594     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  501/   phone)   Gid: (  501/   phone)
Access: 2009-09-22 15:33:15.000000000 +0100
Modify: 2009-05-11 17:01:15.000000000 +0100
Change: 2009-05-11 17:05:09.000000000 +0100

then using the inode number from the Inode line,

find /path -inum 4227594
2
  • Sorry, your answer is not clear. Inode is the same for all hardlinks? Sep 24, 2009 at 9:26
  • great ! ( ls -i could do instead of stat )
    – dugres
    Sep 24, 2009 at 9:35
0

For hardlinks only:

find -samefile xaa -ls

to also include symlinks:

find -L -samefile xaa -exec ls -li {} \;

Using -exec ls here instead of -ls shows the owner, group, permissions and target of the symlinks themselves instead of the information of the target.

You must log in to answer this question.

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