• lsof恢复被删除的文件


    加微信:fuye-waiwang;免费试用梯子;副业承诺不收一毛佣金。

    首先声明:lsof只能恢复哪些文件系统正在处理的,就是系统对其是打开状态的文件。

    比如你自己删除一个txt文件,是很难恢复的。

    好了,直接上干货

    1、比如我建量一个脚本11.sh

    #!/bin/bash
    while true
    do
    sleep 1
    echo t > test.txt
    done

    2、系统过来查看脚本运行的信息

     ~]# lsof|grep 11.sh

    lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /home/libyadm/.gvfs
    Output information may be incomplete.
    bash 17936 root 255r REG 253,0 80 134462272 /root/etcd/11.sh 

    3、删除脚本11.sh;再次查看。

     ~]# lsof|grep 11.sh

    lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /home/libyadm/.gvfs
    Output information may be incomplete.
    bash 17936 root 255r REG 253,0 80 134462272 /root/etcd/11.sh (deleted)

    已经是删除状态了。

    4、我们恢复这个文件

    ~]# cd /proc/17936/fd
    attr/ cwd/ fd/ fdinfo/ map_files/ net/ ns/ root/ task/

    查看

    # ll
    total 0
    lrwx------ 1 root root 64 Nov 26 13:51 0 -> /dev/pts/2
    lrwx------ 1 root root 64 Nov 26 13:51 1 -> /dev/pts/2
    lrwx------ 1 root root 64 Nov 26 13:51 2 -> /dev/pts/2
    lr-x------ 1 root root 64 Nov 26 13:51 255 -> /root/etcd/11.sh (deleted)
    lrwx------ 1 root root 64 Nov 26 13:51 6 -> /dev/pts/2

    我们这里恢复这个文件内容

    cat 255 > /root/etcd/test/11.sh

    至此,恢复工作ok量。只要系统一直打开这个文件就好说。比较适合用于数据库,系统日志之类的误删恢复操作。

  • 相关阅读:
    [WC2010]重建计划
    [POJ1741]Tree
    [NOI2008]志愿者招募
    [BZOJ2127]happiness
    「网络流 24 题」太空飞行计划
    [TJOI2015]线性代数
    [HDU2874]Connections between cities
    [POI2007]ZAP-Queries
    [SCOI2010]幸运数字
    POJ 2826 An Easy Problem?!
  • 原文地址:https://www.cnblogs.com/xingyunfashi/p/14041990.html
Copyright © 2020-2023  润新知