Let's say I have two hard links pointing at the same picture.


What happens if I edit /photography/picture_1.jpg? Is the hard link broken and did I end up with 2 different files? Does it keep the link and therefore edit the "second" file, accessed by the second pointer?

  • What editing tool are you using? This is a behavioural difference amongst editing tools (well known for text editors, but of course applicable for all kinds of content editing utilities). – JdeBP Dec 13 '15 at 6:40
  • Thak you. I'm using different editors, mostly Geany, Gedit, Vim, LibreOffice, but also Pinta... I'm not sure about Owncloud either (see comment below). – mxdsp Dec 13 '15 at 13:27

A hard link is simply an alternative name for the same inode (file). Editing the file found at either of those paths will change the picture that both paths point to.

A soft/symbolic link is different: it's a pointer to the original file and can be broken. A hard link is not a pointer to the file, it is the same file under a different name.

However, some editing tools may use temporary files (as opposed to true, in-place editing) to create and save your edits. So it may end up being dependent on the tool you use. You can experiment with your editor of choice and see if it changes a file's inode number after editing. Find out a file's inode number from the output of ls -i filename (Thanks to Sparhawk's comment for that note).

See also:

| improve this answer | |
  • 2
    I think this is dependent on the program used. For example, if you edit with something like gimp, I suspect (not tested) that since it "exports" to jpeg, it'd overwrite with a new file, rather than a true "edit". – Sparhawk Dec 13 '15 at 8:00
  • @Sparhawk Interesting. Thanks for the info. I will edit the answer to reflect that. – Joseph R. Dec 13 '15 at 8:03
  • Well, I was thinking generally. Well I would like to know what does Geany, Gedit, Vim, LibreOffice, but also Pinta... I'm not sure about Owncloud either, what if I edit a file on line and sync it... I'm going to try things a bit. I might have abuse of hardlinks to save space before asking that question. Could that be a good question to ask for a list of common programs/behavior regarding to that question ? – mxdsp Dec 13 '15 at 13:20
  • @mxdsp could be. As I told you, it should be relatively easy to treat it for yourself. – Joseph R. Dec 13 '15 at 19:57

Your Answer

