3

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

dugres
  • 241
  • 3
  • 8

4 Answers4

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.

Dan Carley
  • 25,617
  • 5
  • 53
  • 70
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
Ryaner
  • 3,097
  • 5
  • 25
  • 33
3
find /partition_root -samefile /partition_root/file/to/find/hardlinks/of
womble
  • 96,255
  • 29
  • 175
  • 230
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.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151