技術員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機純凈版,64位旗艦版,綠色軟件,免費軟件下載基地!

當前位置:主頁 > 教程 > 服務器類 >

Linux 從進程相關的文件描述中恢復數(shù)據(jù)

來源:技術員聯(lián)盟┆發(fā)布時間:2018-10-27 18:18┆點擊:

在Linux中誤刪除了某個文件,但是 ps-ef|grep 文件名 發(fā)現(xiàn)某個進程還在使用該文件,那么可以通

過以下方式恢復文件。

例如:
創(chuàng)建一個簡單文件/tmp/test.txt, 隨便向里面寫點內容

兩個client模擬,client1 負責打開文件less /tmp/test.txt(模擬占用線程)

client2 負責恢復文件

恢復步驟(均在client2上執(zhí)行)

1. 查看/tmp/test.txt被占用的進程id

[root@host tmp]# ps -ef|grep test.txt
root     31631 31539  0 09:35 pts/0    00:00:00 less test.txt
root     31649 31579  0 09:36 pts/1    00:00:00 grep test.txt

2. cd /proc/31631/fd 文件夾中

3. 執(zhí)行l(wèi)l命令

[root@host fd]# ll
total 0
lrwx------ 1 root root 64 Dec  3 09:36 0 -> /dev/pts/0
lrwx------ 1 root root 64 Dec  3 09:36 1 -> /dev/pts/0
lrwx------ 1 root root 64 Dec  3 09:36 2 -> /dev/pts/0
lr-x------ 1 root root 64 Dec  3 09:36 3 -> /dev/tty
lr-x------ 1 root root 64 Dec  3 09:36 4 -> /tmp/test.txt (deleted)

4. 發(fā)現(xiàn)了4是軟連接到 /tmp/test.txt 文件中的

cat 4 即可找到刪除的文件內容

以下是/proc目錄中進程N的信息
/proc/N/cmdline 進程啟動命令 
/proc/N/cwd 鏈接到進程當前工作目錄
/proc/N/environ 進程環(huán)境變量列表
/proc/N/exe 鏈接到進程的執(zhí)行命令文件
/proc/N/fd 包含進程相關的所有的文件描述符
/proc/N/maps 與進程相關的內存映射信息
/proc/N/mem 指代進程持有的內存,不可讀
/proc/N/root 鏈接到進程的根目錄
/proc/N/stat 進程的狀態(tài)
/proc/N/statm 進程使用的內存的狀態(tài)
/proc/N/status 進程狀態(tài)信息,比stat/statm更具可讀性
/proc/self 鏈接到當前正在運行的進程