目錄
- 方法一
- 方法二
不小心執行了
rm洗掉了某些檔案,是有點倒霉,不過我一般都會設定alias rm='rm -i'在洗掉的時候需要輸入Y才能真正洗掉,當然此時用rm -f那也會直接洗掉了,
因此找了兩種方案恢復誤刪的檔案,
方法一
適用系統內置debugfs,適用于洗掉不久,檔案inode還存在的方式,
1.往檔案中寫入資料
root@janbar:~/test# date | md5sum > test
2.查看檔案內容
root@janbar:~/test# cat test
462bbd830ae8f1f4ab65bcb644063f11 -
3.洗掉檔案
root@janbar:~/test# rm test
rm: remove regular file 'test'? y
4.查看被洗掉檔案目錄屬于哪個磁區
root@janbar:~/test# df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 57666812 19138652 35575816 35% /
5.執行debugfs工具
root@janbar:~/test# debugfs
debugfs 1.42.13 (17-May-2015)
6.打開磁區
debugfs: open /dev/sda1
7.查看目錄內容,記得一定是絕對路徑,且不能出現 ~ 這種符號
debugfs: ls -d /root/test
2752514 (12) . 2752513 (4084) .. <2759333> (4072) test
<2759335> (4056) test.old
8.將上圖被洗掉檔案的inode號按照下面命令執行,必須為 <> 尖括號括起來的才行
debugfs: logdump -i <2759333>
Inode 2759333 is at group 336, block 11010293, offset 512
Journal starts at block 28111, transaction 578064
Found sequence 565491 (not 578175) at block 29094: end of journal.
9.退出除錯
debugfs: quit
10.執行如下命令可以恢復檔案,bs 為上面的 offset,skip 為上面的 block
root@janbar:~/test# dd if=/dev/sda1 of=/root/test/test.old bs=512 count=1 skip=11010293
1+0 records in
1+0 records out
512 bytes copied, 0.000281056 s, 1.8 MB/s
方法二
grep整個磁區,適用inode丟失,且只能是純文本檔案
1.查看被洗掉檔案目錄屬于哪個磁區
root@janbar:~/test# df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 57666812 19138652 35575816 35% /
2.然后使用grep對磁區進行搜索,需要記得檔案中的某些關鍵字
grep -a -B 30 -A 150 'func main() {' /dev/sda1 > test.go
其中-a表示把磁區看成文本形式(磁區本身是二進制形式的)
-B 30 -A 150表示找到搜索的內容就列印前面30行和后面150行
如果磁區比較大可能需要一定的搜索時間,完成之后打開test.go
幸運的話你會發現在一堆亂碼中鑲嵌著你要恢復的本文
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/256619.html
標籤:其他
下一篇:編程高手是如何練成的?
