Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

up vote 3 down vote accepted
find /partition_root -samefile /partition_root/file/to/find/hardlinks/of
share|improve this answer

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.

share|improve this answer

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
share|improve this answer
    
Sorry, your answer is not clear. Inode is the same for all hardlinks? –  Andrejs Cainikovs Sep 24 '09 at 9:26
    
great ! ( ls -i could do instead of stat ) –  dugres Sep 24 '09 at 9:35

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.