Linux下vim編輯文件時對於上次意外退出的文件的再次開啓編輯的解決方案

1、當我們用遠程工具連接Linux操作系統用vim編輯文件的時候,由於集羣的不穩定,或打開後忘記關閉了,或非正常斷開的時候。當我們再次編輯此文件的時候就會出現如下所示的提示:

[root@localhost scripts]# vim rsync+inotify.sh





E325: ATTENTION
Found a swap file by the name ".rsync+inotify.sh.swp"
          owned by: root   dated: Fri May 17 18:49:14 2019
         file name: /server/scripts/rsync+inotify.sh
          modified: YES
         user name: root   host name: localhost.localdomain
        process ID: 17081 (still running)
While opening file "rsync+inotify.sh"
             dated: Fri May 17 18:45:31 2019

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r rsync+inotify.sh"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".rsync+inotify.sh.swp"
    to avoid this message.

Swap file ".rsync+inotify.sh.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

這是由於已經打開但未關閉的文件,會在其目錄下出現一個.swp的文件,由於是屬於隱藏文件,可以用命令“l.”對其進行查看。需要將該.swp文件進行刪除,纔不會出現上述中的那些提醒。

2、解決方案

查看並刪除.swp隱藏文件

[root@localhost scripts]# l.
.  ..  .rsync+inotify.sh.swp
[root@localhost scripts]# rm -rf .rsync+inotify.sh.swp

由於是隱藏的文件,所以不能夠使用rm -rf *.swp這樣的形式進行刪除;

但是可以使用語句:rm -rf .*.swp  的形式進行刪除

刪除該文件的.swp隱藏文件之後就可以正常打開和編輯該文件了。

[root@localhost scripts]# vim rsync+inotify.sh 

#!/bin/bash
#qq:1431975440
#rsync+inotify
serverID=10.90.3.115
back_path=/data
rsync_module=oldboy
rsync_user=rsync_backup
rsync_passwd=/etc/rsync.password
inotify_path=/opt/inotify/bin/inotifywait




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章