Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I edit a file in "vi" editor the inode value of the file is changing. But when edited with cat command the inode value is not changing.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Most likely, you have set the backup option on, and backupcopy to "no" or "breakhardlink".

share|improve this answer
    
how to remove that option –  monu Apr 15 '12 at 11:17
2  
@monu, edit your ~/.vimrc. Those are not the default settings. –  cjm Apr 15 '12 at 16:20

When you want to modify a file, you have two options, each with its benefits and drawbacks.

  • You can overwrite the file in place. This does not use any extra space, and conserves the hard links, permissions and any other attribute beyond the content of the existing file. The major drawback of doing this is that if anything happens while the file is being written (the application crashes, or the power goes out), you end up with a partially written file.
  • You can write the new version of the file to a new file with a different name, then move it into place. This uses more space and breaks hard links, and if you have write permissions on a file but not on the directory it contains, you can't do it at all. On the flip side, the old version of the file is atomically replaced by the new version, so at every point in time the file name points to a valid, complete version of the file.

Advanced editors such as Vim or Emacs can choose between the two methods. When they use the first method, they normally make a backup file first, which can be recovered if the new file contents cannot be written correctly.

Classical vi overwrites the file in place. So the inode is unchanged.

In Vim, as cjm has already stated, the choice is controlled by the backup, backupcopy and writebackup options. By default, Vim renames the old file, then writes a new file with the original name, if it thinks it can re-create the original file's attributes. If you want to reuse the existing inode (and so risk losing data, or waste more time making a backup copy), add set backupcopy yes to your .vimrc.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.