zoukankan      html  css  js  c++  java
  • 【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博客

  • 相关阅读:
    C#中Split用法
    ASP.NET Get和Post两种提交的区别:
    BAT常用命令
    SQL语句:在两个数据库间复制表结构和数据数据库
    C#中Array与ArrayList用法及转换
    找出输入区间内的回文质数
    (转)加藤嘉一:中国大学生,你没资格抱怨政府
    最长公共子序列(LCS)
    shell(希尔)排序
    关于Ubuntu中google chrome浏览器字体的设置
  • 原文地址:https://www.cnblogs.com/happyamyhope/p/9628904.html
Copyright © 2011-2022 走看看