惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 舒方小院

六一新玩具 some interesting words [原创] 算法题 Zero Sum的一种解法 Linux下压缩不包含路径信息的压缩包 [ZzDW] 关于Java对象序列化您不知道的5件事 [转载] Windows如何在cmd命令行中查看、修改、删除与添加、设置环境变量 [转载] Linux的capability深入分析 [攻略转载] 在飞机上睡觉的七大攻略 [转载] ftp的模式ACTIVE&PASSIVE [转载] QQ黑名单 [转载] Eclipse快捷键 10个最有用的快捷键 [转载] Mysql常用命令行大全 [转载] php java交互 php/java bridge [转载] MySQL命令行下执行.sql脚本详解 [转载] rpm 常用命令 [转载] 控制寄存器(CR0,CR1,CR2,CR3,CR4) [转载] 汇编中AREA和ENTRY理解 [转载] Centos下如何解包rpm文件 生命期是个不可大意的问题
[ZzZz && momo] linux 误删 恢复rm -rf
舒方小院 · 2012-10-17 · via 博客园 - 舒方小院

[转载作者说能用]

大多数Linux发行版都提供一个debugfs工具,可以用来对Ext3文件系统进行编辑操作不过在使用这个工具之前,还有一些工作要做。
首先以只读方式重新挂载被误删的文件所在分区。使用如下命令:(假设文件在/usr分区)
mount -r -n -o remount /usr
-r表示只读方式挂载;-n表示不写入/etc/mtab,如果是恢复/etc上的文件,就加上这个参数。如果系统说xxx partion busy,可以用fuser命令查看一下是哪些进程使用这个分区上的文件:
fuser -v -m /usr
如果没有什么重要的进程,用以下命令停掉它们:
fuser -k -v -m /usr
然后就可以重新挂载这些文件系统了。
如果是把所有的文件统一安装在一个大的/分区当中,可以在boot提示符下用linux single进入单用户模式,尽量减少系统进程向硬盘写入数据的机会,要不干脆把硬盘挂在别的机器上。另外,恢复出来的数据不要写到/上面,避免破坏那些有用的数据。如果机器上有dos/windows,可以写到这些分区上面:
mount -r -n /dev/hda1 /mnt/had
然后就可以执行debugfs:(假设Linux在 /dev/hda5)
#debugfs /dev/hda5
就会出现debugfs提示符debugfs:
使用lsdel命令可以列出很多被删除的文件的信息:
debugfs:lsdel
debugfs: 2692 deleted inodes found.
Inode Owner Mode Size Blocks Time deleted
164821 0 100600 8192 1/ 1 Sun May 13 19:22:46 2001
…………………………………………………………………………………
36137 0 100644 4 1/ 1 Tue Apr 24 10:11:15 2001
196829 0 100644 149500 38/ 38 Mon May 27 13:52:04 2001

debugfs:
列出的文件有很多(这里找到2692个),第一字段是文件节点号,第二字段是文件所有者,第三字段是读写权限,接下来是文件大小,占用块数,删除时间。然后就可以根据文件大小和删除日期判断那些是我们需要的。比如我们要恢复节点是196829的文件:
可以先看看文件数据状态:
debugfs:stat
Inode: 196829 Type: regular Mode: 0644 Flags: 0x0 Version: 1
User: 0 Group: 0 Size: 149500
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 38
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x31a9a574 -- Mon May 27 13:52:04 2001
atime: 0x31a21dd1 -- Tue May 21 20:47:29 2001
mtime: 0x313bf4d7 -- Tue Mar 5 08:01:27 2001
dtime: 0x31a9a574 -- Mon May 27 13:52:04 2001
BLOCKS:
594810 594811 594814 594815 594816 594817 ………………………………….
TOTAL: 38
然后就可以用dump指令恢复文件:
debugfs:dump /mnt/hda/01.sav
这样就把文件恢复出来了。退出debugfs:
debugfs:quit
另一种方法是手工编辑inode:
debugfs:mi
Mode [0100644]
User ID [0]
Group ID [0]
Size [149500]
Creation time [0x31a9a574]
Modification time [0x31a9a574]
Access time [0x31a21dd1]
Deletion time [0x31a9a574] 0
Link count [0] 1
Block count [38]
File flags [0x0]
Reserved1 [0]
File acl [0]
Directory acl [0]
Fragment address [0]
Fragment number [0]
Fragment size [0]
Direct Block #0 [594810]
…………………………….
Triple Indirect Block [0]
使用mi指令后每次显示一行信息以供编辑,其它行可以直接按回车表示确认,把deletion time改成0(未删除),Link count改成1。改好后退出debugfs:
debugfs:quit
然后用fsck检查/dev/hda5
fsck /dev/hda5
程序会说找到丢失的数据块,放在lost+found里面。'