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?
Asked
Active
Viewed 1,298 times
1
Misguided
- 129
-
1The latter (a copy of the contents, etc). – Thomas Dickey May 07 '19 at 00:44
-
2Remember hardlink is simply another name of the same inode, it IS that inode, not a link to that inode. – 炸鱼薯条德里克 May 07 '19 at 00:47
1 Answers
8
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.
cg909
- 7,082