使用vim進行編輯文件的時候,機器卡死了。然後開機重啓,再次進行vim編輯的時候,總是不能保存,提示“readonly”。當時查看了文件權限,發現文件是可以讀寫操作的。當時就有點迷糊,後來再次進行編輯的時候注意到在編輯之前提示:Another program may be editing the same file,纔想起來可能上次卡死之後,存在臨時文件.swp文件,然後將.swp刪除,就可以繼續進行編輯了。下面是參考的博客(http://www.zongguofeng.cn/2010/0526/309.html)。
linux下兩個人同時打開同一個文件會顯示如下界面,而有的時候只有一個賬戶的時候也有這個提示,此時的處理思路是:由於上次沒有關閉打開的文件造成的,結束掉進程即可
如兩個用戶同時打開:vi install.log 會有一個用戶有此提示
E325: ATTENTION
Found a swap file by the name ".install.log.swp"
owned by: root dated: Sat May 1 10:52:16 2010
file name: ~root/install.log
modified: no
user name: root host name: localhost.localdomain
process ID: 14389 (still running)
While opening file "install.log"
dated: Sat Jan 30 21:31:27 2010
(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 install.log"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".install.log.swp"
to avoid this message.
"install.log" 892L, 33018C
Press ENTER or type command to continue
處理步驟
一、結束進程
[root@localhost ~]# ps -ef |grep vi
root 7177 7156 0 Apr29 tty7 00:00:00 /usr/bin/whiptail --yesno Failed to start the X server (your graphical interface). It is likely that it is not set up
correctly. Would you like to view the X server output to diagnose the problem? 10 50
root 25200 23993 0 22:54 pts/2 00:00:00 vi install.log
root 25234 25197 0 22:55 pts/3 00:00:00 grep vi
[root@localhost ~]# kill -9 25200
You have new mail in /var/mail/root
[root@localhost ~]#
結束進程後仍然有這個提示
E325: ATTENTION
Found a swap file by the name ".install.log.swp"
owned by: root dated: Fri Apr 30 22:54:45 2010
file name: ~root/install.log
modified: no
user name: root host name: localhost.localdomain
process ID: 25200
While opening file "install.log"
dated: Mon Mar 9 03:06:01 2009
(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 install.log"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".install.log.swp"
to avoid this message.
"install.log" 1079L, 45902C
Press ENTER or type command to continue
步驟二:
此時是由於緩存造成的刪除緩存即可(註明此時的緩存文件在你打開的文件位置並不一定是當前的位置)
[root@localhost ~]# rm -rf .install.log.swp
此時即可打開即可正常