How can you see the actual hard link by ls?

Solution 1:

You can find inode number for your file with

ls -i

and

ls -l

shows references count (number of hardlinks to a particular inode)

after you found inode number, you can search for all files with same inode:

find . -inum NUM

will show filenames for inode NUM in current dir (.)

Solution 2:

There isn't really a well-defined answer to your question. Unlike symlinks, hardlinks are indistinguishable from the "original file".

Directory entries consist of a filename and a pointer to an inode. The inode in turn contains the file metadata and (pointers to) the actual file contents). Creating a hard link creates another directory entry that references the same inode. These references are unidirectional (in typical filesystems, at least) -- the inode only keeps a reference count. There is no intrinsic way to find out which is the "original" filename.

By the way, this is why the system call to "delete" a file is called unlink. It just removes a hardlink. The inode and attached data are deleted only if the inode's reference count drops to 0.

The only way to find the other references to a given inode is to exhaustively search over the file system checking which files refer to the inode in question. You can use 'test A -ef B' from the shell to perform this check.