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

首頁 > 系統 > Linux > 正文

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

2020-05-27 12:54:31
字體:
來源:轉載
供稿:網友

   原理:在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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云浮市| 麻阳| 河北区| 枞阳县| 台北县| 历史| 仙游县| 胶南市| 安福县| 开原市| 和顺县| 项城市| 阿勒泰市| 辽源市| 崇州市| 闽侯县| 扎囊县| 志丹县| 长治县| 永清县| 平利县| 达州市| 林口县| 和田市| 宜州市| 宜兰县| 延寿县| 灵宝市| 清河县| 新巴尔虎右旗| 泰和县| 桐城市| 尤溪县| 麻栗坡县| 大兴区| 康马县| 昭苏县| 淮北市| 呼玛县| 饶河县| 开鲁县|