Skip to main content

Emacs Breaks Hard Links

I was quite irritated when I found out yesterday that Emacs is breaking hardlinks: Edit a file with two hard links in Emacs, save it and you will end up with two different files.

$ echo abc >first

$ ln first second

$ ll -i
total 8
401320 -rw-r–r– 2 first first 4 Jul 15 15:04 first
401320 -rw-r–r– 2 first first 4 Jul 15 15:04 second

$ emacs first

$ ll -i
total 12
401322 -rw-r–r– 1 first first 17 Jul 15 15:05 first
401320 -rw-r–r– 2 first first 4 Jul 15 15:04 first~
401320 -rw-r–r– 2 first first 4 Jul 15 15:04 second

$ cat first
abc
another line

$ cat second
abc

The reason for this is Emacs renames the original file to first~ and creates a new file first which is not hard-linked to second anymore. I am not sure if this behaviour is such a good idea...