国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

Linux下利用Lsof恢復誤刪文件的方法

2020-07-10 11:56:27
字體:
來源:轉載
供稿:網友
原理:在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

 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 勃利县| 贵溪市| 浦县| 饶平县| 遂平县| 德江县| 全椒县| 开鲁县| 界首市| 西乡县| 保山市| 大渡口区| 双峰县| 镇雄县| 肥东县| 九台市| 五华县| 静乐县| 枝江市| 海晏县| 突泉县| 定州市| 和静县| 博乐市| 垫江县| 那坡县| 奉节县| 瑞安市| 航空| 陕西省| 浠水县| 勃利县| 涞水县| 黎平县| 页游| 西吉县| 南木林县| 乐亭县| 长子县| 巧家县| 漳州市|