linux 下文件误删恢复
linux 下文件误删恢复
0x01 事件背景
某天晚上写代码的时候,本来想删除当前目录下一个叫xxx的文件夹 rm -rdf ./xxx/*, 结果光顾着和人说话,一不留神手贱把命令敲成了rm -rdf ./*. 然后顿时懵逼了,整个目录全没了。心想完蛋了,这个目录有我写了好几天的代码啊,这可怎么是好,问了下周围的人,都说linux下使用-rf的方式删除文件是不可恢复的,叫我放弃,并且重写代码吧。....-_-||。
可我不甘心啊,写了好几天的代码说没就没了,于是Google了下解决方案,网上给出了很多解决方案,有的可行,有的不可行。在反复尝试之后,使用一款名叫exeundelete的工具完成了数据恢复,终于长舒一口气。我将这个工具的使用分享给大家,一是防止下次自己再遇到这种事情不知所措,二十也希望能够帮助到遇到同样问题的朋友。
0x02 extundelete简介
extundelete 是一款可以从ext3或ext4分区恢复已删除的文件的超级实用的开源工具。 ext3和ext4文件系统是Linux发行版中最常见的默认文件系统,如Mint,Mageia或Ubuntu等linux操作系统都在使用这类文件系统。 extundelete使用起来也非常简单,只需要一条命令就可以完成数据恢复。
extundelete下载地址:https://cytranet.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
0x03 编译安装extundelete
extundelete 只提供源码,需要自己进行编译安装才能够使用,整个过程可以由如下的命令完成
$ wget https://cytranet.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
$ tar vxf extundelete-0.2.4.tar.bz2
$ cd extundelete-0.2.4/
$ ./configure
$ make && sudo make install
然后在终端输入extundelete即可看到此工具已经可以使用
sandy@ubuntu:~/Desktop/xxx/extundelete-0.2.4$ extundelete
No action specified; implying --superblock.
extundelete: Missing device name.
Usage: extundelete [options] [--] device-file
Options:
--version, -[vV] Print version and exit successfully.
--help, Print this help and exit successfully.
--superblock Print contents of superblock in addition to the rest.
If no action is specified then this option is implied.
--journal Show content of journal.
--after dtime Only process entries deleted on or after 'dtime'.
--before dtime Only process entries deleted before 'dtime'.
Actions:
--inode ino Show info on inode 'ino'.
--block blk Show info on block 'blk'.
--restore-inode ino[,ino,...]
Restore the file(s) with known inode number 'ino'.
The restored files are created in ./RECOVERED_FILES
with their inode number as extension (ie, file.12345).
--restore-file 'path' Will restore file 'path'. 'path' is relative to root
of the partition and does not start with a '/'
The restored file is created in the current
directory as 'RECOVERED_FILES/path'.
--restore-files 'path' Will restore files which are listed in the file 'path'.
Each filename should be in the same format as an option
to --restore-file, and there should be one per line.
--restore-directory 'path'
Will restore directory 'path'. 'path' is relative to the
root directory of the file system. The restored
directory is created in the output directory as 'path'.
--restore-all Attempts to restore everything.
-j journal Reads an external journal from the named file.
-b blocknumber Uses the backup superblock at blocknumber when opening
the file system.
-B blocksize Uses blocksize as the block size when opening the file
system. The number should be the number of bytes.
--log 0 Make the program silent.
--log filename Logs all messages to filename.
--log D1=0,D2=filename Custom control of log messages with comma-separated
Examples below: list of options. Dn must be one of info, warn, or
--log info,error error. Omission of the '=name' results in messages
--log warn=0 with the specified level to be logged to the console.
--log error=filename If the parameter is '=0', logging for the specified
level will be turned off. If the parameter is
'=filename', messages with that level will be written
to filename.
-o directory Save the recovered files to the named directory.
The restored files are created in a directory
named 'RECOVERED_FILES/' by default.
0x04 恢复误删文件
编译安装完毕extundelete之后,便可以使用它进行误删文件恢复。首先我们需要找到我们想要恢复的分区,用fdisk等命令可查看分区情况
sandy@ubuntu:~/Desktop/xxx/extundelete-0.2.4$ sudo fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe184ba74 Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 79693823 79691776 38G 83 Linux
/dev/sda2 79695870 83884031 4188162 2G 5 Extended
/dev/sda5 79695872 83884031 4188160 2G 82 Linux swap / Solaris
sandy@ubuntu:~/Desktop/xxx/extundelete-0.2.4$
其中/dev/sda1是我想进行恢复的分区,因为刚才删除的文件位于其中。接着便是使用extundelete进行数据恢复,使用下面这条命令:
sudo extundelete /dev/sda1 --restore-all #恢复所有数据
运行完毕之后,在当前目录下会生成一个名叫11的目录,里面保了我们所有删除的数据
sandy@ubuntu:~/Desktop/xxx/extundelete-0.2.4$ ll RECOVERED_FILES/
total 3888
drwxr-xr-x 3 root root 4096 Apr 10 18:49 home/
drwxr-xr-x 198 root root 118784 Apr 10 18:50 lost+found/
drwxr-xr-x 6 root root 4096 Apr 10 18:49 tmp/
drwxr-xr-x 7 root root 4096 Apr 10 18:49 usr/
drwxr-xr-x 5 root root 4096 Apr 10 18:49 var/
sandy@ubuntu:~/Desktop/xxx/extundelete-0.2.4$
可以看到删除的文件都被恢复了。
0x05 总结
即便是extundelete这样的神器,也无法做到100%的数据恢复。这一次的经历,算是有惊无险,还好数据恢复了,不然几天的工作就付之东流了。总结一下,重要的数据注意备份,保证自己数据不丢失。如果没有备份再被误删,要是连extundelete这样的工具都无法恢复,那就只能呵呵了。
0x06 参考文章
- http://extundelete.sourceforge.net/
- https://unix.stackexchange.com/questions/122305/undelete-a-just-deleted-file-on-ext4-with-extundelete
欢迎加入程序设计交流与分享qq技术交流群:439261058
我的邮箱1215714557@qq.com,欢迎交流指正
linux 下文件误删恢复的更多相关文章
- Linux下文件误删除恢复案例
说明:将/etc/profile文件删除,然后恢复 在linux中为什么讲文件删除还能恢复呢? 详见:文件删除原理 http://blog.csdn.net/grantlee1988/article/ ...
- linux 下文件重命名/移动/复制命令(转)
linux 下文件重命名/移动/复制命令(转) linux下重命名文件:使用mv命令就可以了, 例:要把名为:abc 重命名为:123 可以这样操作: 重命名:MV命令 1.进入你的文件目录,运行 ...
- (转)linux下文件删除的原理精华讲解(考试题答案系列)
linux下文件删除的原理精华讲解(考试题答案系列) 说明:本文为老男孩linux培训某节课前考试试题及答案分享博文内容的一部分,也是独立成题的,你可以点下面地址查看全部的内容信息.http://ol ...
- Linux下文件的三种时间戳
Linux下文件的三种时间标记 三种时间对应关系表 column column column 访问时间 Access atime 修改时间 Modify mtime 状态改动时间 Change cti ...
- linux下文件结束符
linux下文件结束符,我试过了所有的linux,发现其文件的结束符都是以0a即LF结束的,这个是操作系统规定的,windows下是\r\n符结束,希望可以帮助大家. -------------转:来 ...
- dos2unix,去掉Linux下文件中的^M
Windows系统下使用VS2010编写好的CPP文件,想放到Linux上进行编译.发现Linux上文件中的每行代码末尾都跟着^M这个符号. 为什么同一份文件在windows上和Linux上显示的不一 ...
- linux下文件的复制、移动与删除
linux下文件的复制.移动与删除命令为:cp,mv,rm 一.文件复制命令cp 命令格式:cp [-adfilprsu] 源文件(source) 目标文件(destination) ...
- Linux下文件的权限
一.Linux下查看文件属性 命令为: [root@localhost ~]# ls -al 结果: ls是『list』的意思,重点在显示文件的文件名与相关属性.而选项『-al』则表示列出所有的文件详 ...
- Windows与Linux下文件操作监控的实现
一.需求分析: 随着渲染业务的不断进行,数据传输渐渐成为影响业务时间最大的因素.究其原因就是因为数据传输耗费较长的时间.于是,依托于渲染业务的网盘开发逐渐成为迫切需要解决的需求.该网盘的实现和当前市场 ...
随机推荐
- Flask 测试
测试是每个应用系统发布前必须经历的步骤,自动化测试对测试效率的提高也是毋庸置疑的.对于Flask应用来说,当然可以使用Web自动化测试工具,比如Selenium等来测.Flask官方推荐的自动化测试方 ...
- 谈谈ASP.NET Core中的ResponseCaching
前言 前面的博客谈的大多数都是针对数据的缓存,今天我们来换换口味.来谈谈在ASP.NET Core中的ResponseCaching,与ResponseCaching关联密切的也就是常说的HTTP缓存 ...
- zuul入门(3)开发zuul的过滤器
1.编写Zuul过滤器(Java&Groovy) 理解过滤器类型和请求生命周期后,我们来编写一个Zuul过滤器.编写Zuul的过滤器非常简单,我们只需继承抽象类ZuulFilter,然后实现几 ...
- .NET CORE 框架ABP的代码生成器(ABP Code Power Tools )使用说明文档
前言 各位好,又是一个多月没更新文章了. 原因嘛,大家都懂的,太忙了~ 临近年末,公司的项目.年会的做技术支持,同事朋友聚餐也比较频繁. 当然视频教程也没有继续更新.我的锅~ 但是这个月好歹抽空做了一 ...
- BAT美团滴滴java面试大纲(带答案版)之三:多线程Lock
继续面试大纲系列文章. 这是多线程的第二篇. 多线程就像武学中对的吸星大法,理解透了用好了可以得道成仙,俯瞰芸芸众生:而滥用则会遭其反噬. 在多线程编程中要渡的第二个“劫”,则是Lock.在很多时候, ...
- Spring之AOP编程
一.AOP简介 AOP的英文全称是Aspect Oriented Programming,意为:面向切面编程. AOP采取横向抽取的机制,取代了传统纵向继承体系的代码复用.AOP常用于 ...
- centos虚拟机nat模式,可以上内网,不能上外网
http://sky425509.iteye.com/blog/1996085 我这边的问题是,好久没用虚拟机了,重启之后,变成了dhcp模式,整个网卡配置变了. 重新配置了静态ip,网关,dns后才 ...
- 记录项目中用的laypage分页代码
最终才觉得,好记性不如烂笔头,毕竟已经不是刚毕业时候的巅峰了,精力有所下降,很多时候记不住东西. 参考url:http://www.layui.com/laypage/ 直接上代码了 <scri ...
- python开发:python基本数据类型
运算符 1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31- ...
- SpringMVC(十一):SpringMVC 处理输出模型数据之SessionAttributes
Spring MVC提供了以下几种途径输出模型数据:1)ModelAndView:处理方法返回值类型为ModelAndView时,方法体即可通过该对象添加模型数据:2)Map及Model:处理方法入参 ...