Welcome to the Linux Foundation Forum!

Modification of files connected by hardlinks


Hello everybody,
in the course there's a sentence:
"Hard links point to an inode.​ All hard linked files have to be on the same filesystem. Changing the content of a hard linked file in one place may not change it in other places."

My question is: why may not?

When I create a hard link, I point to exactly the same inode like the source file, which also is visible on the screen attached to the course (see below, very first column):

All external sources I read say the same: it's a mirror and all changes made are "synchronized": https://cbtnuggets.com/blog/certifications/open-source/linux-hard-links-versus-soft-links-explained, https://ostechnix.com/explaining-soft-link-and-hard-link-in-linux-with-examples/

Can I consider the may not as a mistake in the course?

Best Answer

  • coop
    coop Posts: 915
    Answer ✓

    Because there is software that when it wants to make a modification to a file, it works on a modified copy, removes the old one and copies the new edition to the old location, thus breaking the hard link. This can indeed be bad software and is less common today than it used to be (I remember day-to-day editors that did this.) But it can happen and can lead to catastrophic screw ups. So whatever you read on the Internet, this is something I've learned through experience not to ignore. In fact, a simple "cp" that overwrites the file can break the link.



Upcoming Training