歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux中誤刪除了某個文件後從進程相關的文件描述中恢復數據

Linux中誤刪除了某個文件後從進程相關的文件描述中恢復數據

日期:2017/3/3 16:13:41   编辑:關於Linux

在Linux中誤刪除了某個文件,但是 ps-ef|grep 文件名 發現某個進程還在使用該文件,那麼可以通

過以下方式恢復文件。

例如:

創建一個簡單文件/tmp/test.txt, 隨便向裡面寫點內容

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

client2 負責恢復文件

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

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. 執行ll命令

[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. 發現了4是軟連接到 /tmp/test.txt 文件中的

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

以下是/proc目錄中進程N的信息

/proc/N/cmdline 進程啟動命令

/proc/N/cwd 鏈接到進程當前工作目錄

/proc/N/environ 進程環境變量列表

/proc/N/exe 鏈接到進程的執行命令文件

/proc/N/fd 包含進程相關的所有的文件描述符

/proc/N/maps 與進程相關的內存映射信息

/proc/N/mem 指代進程持有的內存,不可讀

/proc/N/root 鏈接到進程的根目錄

/proc/N/stat 進程的狀態

/proc/N/statm 進程使用的內存的狀態

/proc/N/status 進程狀態信息,比stat/statm更具可讀性

/proc/self 鏈接到當前正在運行的進程

 

Copyright © Linux教程網 All Rights Reserved