Imagine I have a file something/a.txt, which I hardlink from b.txt. Now, if I cp b.txt c.txt, is c.txt a hard link to a.txt, or is it a copy of the contents of a.txt?

  • 1
    The latter (a copy of the contents, etc). – Thomas Dickey May 7 '19 at 0:44
  • 2
    Remember hardlink is simply another name of the same inode, it IS that inode, not a link to that inode. – 炸鱼薯条德里克 May 7 '19 at 0:47

Hardlinks are a completely different concept from other kinds of links or references.

A hardlink is another name to the same inode (a bit simplified: the file contents and metadata).

E.g. if you hardlink a.txt from b.txt, both names a.txt and b.txt are equal names to the same file. After hardlinking you cannot distinguish anymore if a.txt or b.txt was the original file name. Both names point to the same file.

That means cp b.txt c.txt will copy the file contents exactly as if you did cp a.txt c.txt.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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