Linux 文件恢复

可以恢复,使用系统自还工具debugfs来还原删除的文件

步骤详解

1、 查看一下当前系统版本号,及文件系统格式

[root@localhost ~]# df -T 
Filesystem Type 1K-blocks Used Available Use% Mounted on 
/dev/mapper/VolGroup-lv_root 
ext4 51475068 22730068 26123560 47% / 
tmpfs tmpfs 3966808 68 3966740 1% /dev/shm 
/dev/sda2 ext4 487652 42534 419518 10% /boot 
/dev/mapper/VolGroup-lv_home 
ext4 901188872 20070036 835334364 3% /home

2、新建一个文件夹及文件my.txt,然后删除

[root@localhost local]# mkdir test 
[root@localhost local]# cd test 
[root@localhost test]# touch my.txt 
[root@localhost test]# ll 
总用量 0 
-rw-r–r–. 1 root root 0 1月 4 15:22 my.txt 
[root@localhost test]# rm -f my.txt 
[root@localhost test]# ll 
总用量 0

3、运用,系统自还工具debugfs来修复 打开,刚刚被删除文件所在的分区,用ls 加-d参数显示刚刚删除文件所在的目录

[root@localhost test]# debugfs 
debugfs 1.41.12 (17-May-2010) 
debugfs: open /dev/mapper/VolGroup-lv_root 
debugfs: ls -d /usr/local/test/ 
2378807 (12) . 2098175 (4084) .. <2378808> (4072) my.txt

4、显示有<>尖括号的就是我们要找的文件Inode 号 执行logdump –i <2378808>,然后输入“quit”退出debugfs

debugfs: logdump -i <2378808> 
Inode 2378808 is at group 290, block 9438337, offset 2944 
Journal starts at block 16826, transaction 2237277 
No magic number at block 30648: end of journal. 
debugfs: quit

5、执行以下命令,进行恢复,bs与skip的值分别取自:block 9438337, offset 2944

dd if=/dev/mapper/VolGroup-lv_root of=/usr/local/test/my.txt bs=2944 count=1 skip=9438337

bs对应上面的offset后面的值,skip对应block后面的值

debugfs: quit 
[root@localhost test]# dd if=/dev/mapper/VolGroup-lv_root of=/usr/local/test/my.txt bs=2944 count=1 skip=9438337 
记录了1+0 的读入 
记录了1+0 的写出 
2944字节(2.9 kB)已复制,0.00989032 秒,298 kB/秒 
[root@localhost test]# ls 
my.txt

至此,刚删除的数据已恢复

转载于:https://www.cnblogs.com/wanghaiyang1930/p/10496128.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值