linux 誤刪文件恢復(fù)方法(debugfs)

應(yīng)用linux自帶工具debugfs恢復(fù)誤刪文件方法演示

1.創(chuàng)建一個(gè)文件寫(xiě)入內(nèi)容并刪除

cj@cj-virtual-machine:~/Documents/debugfs_example$ vim 1.c
cj@cj-virtual-machine:~/Documents/debugfs_example$ ls
1.c
cj@cj-virtual-machine:~/Documents/debugfs_example$ rm 1.c

2.查看文件所在分區(qū)

cj@cj-virtual-machine:~/Documents/debugfs_example$ df ./
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       41020640 23113464  15793744  60% /

3.啟動(dòng)debugfs工具

cj@cj-virtual-machine:~/Documents/debugfs_example$ sudo debugfs
debugfs 1.44.1 (24-Mar-2018)
debugfs:  open /dev/sda1
debugfs:  ls -d /home/cj/Documents/debugfs_example/

若提示權(quán)限問(wèn)題無(wú)法打開(kāi)分區(qū),請(qǐng)使用root權(quán)限打開(kāi)debugfs工具。
/home/cj/不可使用~/替代

ls -d 后會(huì)出現(xiàn)如下信息,找到刪除文件1.c,記錄下尖括號(hào)內(nèi)的數(shù)值,按q回到debugfs。

 1574187  (12) .    1576545  (4072) ..   <1582211> (16) .1.c.swp   
<1590178> (4044) 1.c   
(END)

然后使用logdump命令,并使用quit退出debugfs如下

debugfs:  logdump -i <1590178>
Inode 1590178 is at group 194, block 6292541, offset 128
Journal starts at block 33979, transaction 115345
No magic number at block 36187: end of journal.
debugfs:  quit

4.恢復(fù)文件

cj@cj-virtual-machine:~/Documents/debugfs_example$ sudo dd if=/dev/sda1 of=/home/cj/Documents/debugfs_example/1.c bs=128 count=1 skip=629541
1+0 records in
1+0 records out
128 bytes copied, 0.000390194 s, 328 kB/s

bs值為offset
skip值為block
此時(shí)文件恢復(fù)成功

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 系統(tǒng)管理與維護(hù)命令 date date(選項(xiàng))(參數(shù)) | 選項(xiàng) | 說(shuō)明 | | :-------- | ...
    蓓蓓的萬(wàn)能男友閱讀 4,201評(píng)論 0 5
  • ORA-00001: 違反唯一約束條件 (.) 錯(cuò)誤說(shuō)明:當(dāng)在唯一索引所對(duì)應(yīng)的列上鍵入重復(fù)值時(shí),會(huì)觸發(fā)此異常。 O...
    我想起個(gè)好名字閱讀 6,038評(píng)論 0 9
  • feisky云計(jì)算、虛擬化與Linux技術(shù)筆記posts - 1014, comments - 298, trac...
    不排版閱讀 4,392評(píng)論 0 5
  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,715評(píng)論 19 139
  • 利用app或工具來(lái)記錄睡眠 淺度睡眠時(shí)候喚醒 讓睡眠更有質(zhì)量 時(shí)間管理的基礎(chǔ)是精力管理。精力管理的核心是管理自己的...
    丶尋夢(mèng)閱讀 161評(píng)論 0 0

友情鏈接更多精彩內(nèi)容