【linux】使用swap文件恢复非正常关闭的文件

前言

使用vim的时候,文件编辑过程中可能会出现bug,导致非正常关闭。为了保存刚刚修改的内容,需要对文件进行恢复。

操作过程

1.查看目录文件

zrj@zrj-ThinkPad-E470:~/work/code/facedetection/src$ ll
total 48
drwxrwxr-x 2 xxx xxx  4096 Sep 11 16:48 ./
drwxrwxr-x 6 xxx xxx  4096 Sep 11 12:23 ../
-rw-rw-r-- 1 xxx xxx 10859 Sep 11 16:48 facedet.cpp
-rw-r--r-- 1 xxx xxx 20480 Sep 11 16:43 .facedet.cpp.swp
-rw-rw-r-- 1 xxx xxx 6346 Sep 11 16:44 facedet_test.cpp

发现多了个swap文件。

2.问题描述

E325: ATTENTION
Found a swap file by the name ".facedet.cpp.swp"
          owned by: xxx   dated: Tue Sep 11 16:59:21 2018
         file name: ~xxx/work/code/facedetection/src/facedet.cpp
          modified: no
         user name: xxx   host name: xxx-ThinkPad-E470
        process ID: 22229 (still running)
While opening file "facedet.cpp"
             dated: Tue Sep 11 16:55:31 2018

(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 facedet.cpp"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".facedet.cpp.swp"
    to avoid this message.

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

3.原因分析

a.文件非正常关闭;

b.另一个Terminal也在编辑同一个文件;

 

4解决方法

a.非正常关闭;

使用recover覆盖文件,再删除swap文件;

1. vim -r facedet.cpp
2. rm .facedet.cpp.swp 

b.同时编辑同一个文件;

先关闭一个文件再编辑另一个,注意避免同时编辑同一个文件;

注意,修改文件时请注意避免同一个文件产生两个不同的版本。

参考

1.csdn博客

转载于:https://www.cnblogs.com/happyamyhope/p/9628904.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值