The resulting user of the file depends on what the editor does. Some editors save the file by truncating it, and writing over the file (without changing the inode). And some editors rename the file to another name (file
to file~
is usual), and create a new file with the name of the original. Modifying the original file keeps the owner the same, creating a new one makes the new file owned by the UID of the creating process.
Of the editors I have on Debian, nano
and joe
, as well nvi
and vim
(the minimal version in vim-tiny
) seem to overwrite in-place. Though I suppose vim
and Emacs are probably configurable in what they do.
Stephen comments about atomic updates. The issue with re-creating in-place is that the file is truncated to zero length, then written. Another process could open and read it before all data is written.
An atomic update would be done by creating the new version as say file.new
, then renaming file.new
to file
. Leaving a backup file, one could create file.new
, link file
to file~
and then rename file.new
to file
. The rename is atomic in that any process that accesses the file by name gets either the old or the new version, not anything in between. Any open file handles will of course point to the file that was held open, giving a consistent view on the file.
From the file permissions point of view, saving over the same file (inode) requires write access to the file itself (but not the directory), renaming it and creating a new one requires write access to the directory (but not to the original file).
(Renaming and recreating is also incidentally a way of fixing file permissions in case someone creates or modifies a file in a shared directory, but forgets to give group write access to it.)