linux swap file “*.swp”already exists!问题

在 Linux 下的 vi 编辑过程中,由于某种原因异常退出正在编辑的文件,再次编辑该文件时,会出现如下提示:

E325: ATTENTION
Found a swap file by the name ".test1.sh.swp"
          owned by: lee   dated: Sat Oct 31 10:49:13 2020
         file name: ~lee/shell_test/test1.sh
          modified: YES
         user name: lee   host name: localhost.localdomain
        process ID: 55555
While opening file "test1.sh"
             dated: Mon Jan 11 14:24:56 2021
      NEWER than swap file!

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

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

这是因为使用vi编辑文件实际是先 copy 一份临时文件并映射到内存给你编辑, 编辑的是临时文件,;
当执行:w 后才保存临时文件到原文件,执行:q 后才删除临时文件。

每次启动检索是否有临时文件, 有则询问如何处理,就会出现如上情景,换言之就是你在上一次编辑过程中因一些莫名原因强制退出了正在编译的文件导致的(切记保留规范的开发使用习惯)。

解决办法:
删除临时文件*.swp

[lee@localhost shell_test]$ ll -a
total 20
drwxrwxr-x   2 lee lee    43 Jan 11 14:31 .
drwx------. 22 lee lee  4096 Jan 11 14:31 ..
-rw-rw-r--   1 lee lee    33 Jan 11 14:24 test1.sh
-rw-r--r--   1 lee lee 12288 Oct 31 10:49 .test1.sh.swp
[lee@localhost shell_test]$ rm -f .test1.sh.swp 
[lee@localhost shell_test]$ ll -a
total 8
drwxrwxr-x   2 lee lee   22 Jan 11 14:31 .
drwx------. 22 lee lee 4096 Jan 11 14:31 ..
-rw-rw-r--   1 lee lee   33 Jan 11 14:24 test1.sh

此时就能重新vi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

D2cOneluo

万一有大佬给个打赏呢,对不对。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值