我使用 Vim 8.2 在我的 Ubuntu 18.04 中编辑我的文件。当我打开一个文件,做一些更改并用 Vim 退出时,这个文件的 inode 号将被更改。
据我了解,是因为我的Vim开启了备份机制,所以每个版本都会创建一个新的文件(.swp
file)来替换旧的。一个新文件有一个新的 inode 编号。就是这样。
但是我发现了一些奇怪的东西。
如下所示,在第一个 之后vim 11.cpp
,inode 发生了变化,409980
变成了409978
. 但是,在为文件创建硬链接后11.cpp
,无论我如何11.cpp
使用 Vim修改文件,其 inode 编号都不会再更改。如果我删除了硬链接xxx
,它的 inode 编号将被我的 Vim 的每个版本再次更改。
这真的让我很困惑。
$ ll -i ./11.cpp
409980 -rw-rw-r-- 1 zyh zyh 504 Dec 22 17:23 ./11.cpp
$ vim 11.cpp # append a string "abc" to the file 11.cpp
$ ll -i ./11.cpp
409978 -rw-rw-r-- 1 zyh zyh 508 Dec 22 17:25 ./11.cpp
$ vim ./11.cpp # remove the appended "abc"
$ ll -i ./11.cpp
409980 -rw-rw-r-- 1 zyh zyh 504 Dec 22 17:26 ./11.cpp
$ ln ./11.cpp ./xxx # create a hard link
$ ll -i ./11.cpp
409980 -rw-rw-r-- 2 zyh zyh 504 Dec 22 17:26 ./11.cpp
$ vim 11.cpp # append a string "abc" to the file 11.cpp
$ ll -i ./11.cpp
409980 -rw-rw-r-- 2 zyh zyh 508 Dec 22 17:26 ./11.cpp
$ vim 11.cpp # remove the appended "abc"
$ ll -i ./11.cpp
409980 -rw-rw-r-- 2 zyh zyh 504 Dec 22 17:26 ./11.cpp
似乎设置backupcopy
是auto
(:set backupcopy?
在 Vim 中运行以确认)。
主要值是:
yes
制作文件的副本并覆盖原始
no
文件,重命名文件并写入前一个新文件
auto
,哪种效果最好[…]
该
auto
值是中间方式:当 Vim 看到可以在没有副作用的情况下重命名文件(属性可以传递并且文件不是链接)时使用。当预计出现问题时,将制作一份副本。
如果不清楚:(yes
复制和覆盖)不会更改 inode 编号,no
(重命名并重新写入)会更改它。
在你的情况下,起初auto
就像no
. 在ln ./11.cpp ./xxx
Vim注意到有另一个链接并auto
像yes
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句