[cs631apue] problem about hard link
Jan Schaumann
jschauma at stevens.edu
Fri Sep 21 11:32:55 EDT 2012
yluo4 <yluo4 at stevens.edu> wrote:
> I find a file named 'file2~' is created automatically and his name is
> blue.
Colors are really irrelevant here, as they may be complete different
from one user to another based on their preferences. Unix does not in
any way associate color with file attributes.
> When I open it using emacs, it only contains 'moo' and it is
> read-only.
Yes, emacs creates a backup when it edits a file. It seems that it
actually does the following:
ln file2 file1
emacs file1
mv file1 file1~
cp file1~ file1
edit file1
Hence the inode will be the same for your file2 and file1~ (mv renamed
the inode-filename mapping in the directory), but different for the
newly created 'file1' (cp creates a new file mapping to a new inode
number).
This certainly is unexpected, and other editors do not exhibit this
behaviour.
-Jan
More information about the cs631apue
mailing list