Let's say I have two files file1
and file2
:
$ echo aaa >file1
$ ln file1 file2
Then I check that the inodes are the same:
$ ls -i
18749779 file1 18749779 file2
which shows that the two files are actually the same. Now I edit file1
in Emacs, and add a line with for example the text bbb
, and save it and exit Emacs.
Now I get:
$ ls -i
18749781 file1 18749779 file2
$ cat file1
aaa
bbb
$ cat file2
aaa
So the hard link is broken. Note that this does not happen when I edit the file in vim
, or if I simply do echo bbb >>file1
..
How can I prevent Emacs from breaking hard links?
Update:
Note that I have
(require 'backup-dir)
(setq bkup-backup-directory-info
'((t "~/.emacs-backups/" ok-create full-path )))
in my ~/.emacs
init file. If I edit file1
using emacs -Q file1
instead, I get a file called file1~
in the current directory that links to file2
(has the same inode) but the file1~
has not been modified (so it is identical to the old file1
).. This is not what I desire. I would like both file1
and file2
to be the same file, and to include the updated file contents..