You are not logged in.
Pages: 1
If a file has two hard links and I edit it, should there still be two links to it?
For example, when I do do the following "a" and "b" have the same inode:
sh-3.2$ echo foo > a
sh-3.2$ ln a b
sh-3.2$ echo bar >> b
sh-3.2$ ls -i
14049345 a 14049345 b
However if I edit a file with gnumeric I get different inodes:
sh-3.2$ gnumeric
Writing file:///a.gnumeric
sh-3.2$ ln a.gnumeric b.gnumeric
sh-3.2$ gnumeric b.gnumeric
Reading file:///b.gnumeric
Writing file:///b.gnumeric
sh-3.2$ ls -i
14049346 a.gnumeric 14049347 b.gnumeric
Would this be considered a bug in gnumeric? Should I not expect the two files to stay linked? I'm not really sure how to use hard links with the two different behaviors.
Offline
No, apparently this is the recommended way of doing things.
Edit: You would expect Gnumeric to edit the file in place. What I think it is doing is replacing the entire contents of the file on write. I'm not sufficiently familiar with Gnumeric to explain why they chose this way. I can tell you this is the reason why the inodes are different.
Last edited by fsckd (2010-08-09 16:24:45)
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
In a nutshell: There is not likely to be enough space to edit the file in-place without lots of fragmentation, so most editors and userspace programs save modified copies rather than making in-place edits.
On the other hand, when you edit a file with Emacs or by using the -i flag to Perl or sed or any of a number of other command line apps, the original file is renamed without copying.
% ls -i text
132109 text
% sed -i~ -e 's/e//' text
% ls -i text*
132108 text 132109 text~
In this example, the original file was renamed and the modified copy was saved with the original name to a different inode.
Offline
% ls -i text 132109 text % sed -i~ -e 's/e//' text % ls -i text* 132108 text 132109 text~
In this example, the original file was renamed and the modified copy was saved with the original name to a different inode.
Nice example and explanation.
Offline
Pages: 1