zoukankan      html  css  js  c++  java
  • 恢复误删的进程在使用的文件

    原理:在Linux系统的/proc 分区下保存着进程的目录和名字,包含fd(文件描述符)和其下的子目录(进程打开文件的链接),那么如果删除了一个文件,还存在一个 inode的引用:/proc/进程号/fd/文件描述符。我们只要知道当前打开文件的进程pid和文件描述符fd就能利用lsof工具列出进程打开的文 件。
    一、将 ls 的手册过滤掉主要控制符后重定向到文件ls.txt 中,并用more查看,CTRL + Z 暂停查看操作
    1: [root@localhost script]# man ls |col -b > ls.txt
    2: [root@localhost script]# more ls.txt
    3: LS(1) User Commands LS(1)
    4:
    1: [1]+ Stopped more ls.txt
    2: [root@localhost script]#
    3: [root@localhost script]# jobs
    4: [1]+ Stopped more ls.txt
    5:
    二、假设误删文件 ls.txt
    1: [root@localhost script]# rm ls.txt
    2: rm:是否删除 一般文件 “ls.txt”? y
    三、利用lsof找到进程6511、并拷贝恢复,只能在这个文件被使用或调用的情况下有效
    3: [root@localhost script]# lsof |grep ls.txt
    4: more 6511 root 3r REG 253,0 7300 1083699 /opt/script/ls.txt (deleted)
    5:
    1: [root@localhost script]# ls -l /proc/6511/fd/
    2: 0 1 2 3
    3: [root@localhost script]# ls -l /proc/6511/fd/3
    4: lr-x------ 1 root root 64 10-30 21:21 /proc/6511/fd/3 -> /opt/script/ls.txt (deleted)
    5:
    1: cp /proc/6511/fd/3 ls.txt.saved

  • 相关阅读:
    014_Python3 循环语句
    013_Python3 条件控制
    012_Python3 斐波纳契数列 + end 关键字
    011_Python3 集合
    010_Python3 字典
    009_Python3 元组
    008_Python3 列表
    006_Python3 数字(Number)
    005_Python3 运算符
    bzoj3160
  • 原文地址:https://www.cnblogs.com/276815076/p/5473185.html
Copyright © 2011-2022 走看看