vim Another program may be editing the same file.

使用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


此时即可打开即可正常


你可能感兴趣的:(杂七杂八)