為什么vi編輯后文件的Birth Time也會變?

1、問題現(xiàn)象

VI編輯后 Acess、Modify、Change和Birth Time都會變


image.png

其原因是 vi后,文件的inode會發(fā)生變化


image.png

這種情況如果發(fā)生在日志文件上,就會出現(xiàn)新日志不會記錄到日志文件,而且日志空間還會繼續(xù)上漲


image.png

2、inode為什么會變?

缺省情況下,backupcopy=auto,一般是no,也就是會寫一個新文件

'backupcopy' 'bkc'      string  (Vi default for Unix: "yes", otherwise: "auto")
                        global or local to buffer |global-local|
                        {not in Vi}
        When writing a file and a backup is made, this option tells how it's
        done.  This is a comma separated list of words.

        The main values are:
        "yes"   make a copy of the file and overwrite the original one
        "no"    rename the file and write a new one
        "auto"  one of the previous, what works best

        Extra values that can be combined with the ones above are:
        "breaksymlink"  always break symlinks when writing
        "breakhardlink" always break hardlinks when writing
3、如何讓inode不變
  • 在vi中設(shè)置 :set backupcopy=yes
  • 在vimrc (全局或者文件中設(shè)置)
  • 給文件創(chuàng)建硬鏈接
4、已經(jīng)vi編輯過的日志如何找回
  • 通過cp /proc/xxxx/fd/xxxx xxx 找回丟失的日志
  • 找回后重啟應(yīng)用,日志會定位到新的文件
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容