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 学习 六 大型程序结构
pip freeze >requirement.txt 自动生成版本号 pip install -r requirement.txt 自动下载对应的库 梳理结构 config.py #!/usr ...
- Raid 5数据恢复原理以及raid 5数据恢复实际操作案例
Raid 5数据恢复算法原理 要理解 raid 5数据恢复原理首先要先认识raid5,"分布式奇偶校验的独立磁盘结构"也就是我们称之为的raid 5数据恢复有一个概念需要理解,也就 ...
- Mybatis框架入门
Mybaits框架 一.什么是Mybatis MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了googl ...
- 粒子系统(二):Canvas绘制精美图案
准备 IDE:Visual Studio Code Language:JavaScript / ECMAScript 6+ GitHub:Natural2D.JS 本文主要讲述 Particles - ...
- Django快速入门
Django 是用 Python 写的一个自由和开放源码 web 应用程序框架.web框架是一套组件,能帮助你更快.更容易地开发web站点.当你开始构建一个web站点时,你总需要一些相似的组件:处理用 ...
- baidu地图:实现多点连线渲染
<script type="text/javascript"> var points = [ {"Lng":125.17787645967861,& ...
- ZOJ-2750 Idiomatic Phrases Game---Dijk最短路
题目链接: https://vjudge.net/problem/ZOJ-2750 题目大意: 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程 ...
- Java面试题——中级(上)
List和Set比较,各自的子类比较 对比一:Arraylist与LinkedList的比较 1.ArrayList是实现了基于动态数组的数据结构,因为地址连续,一旦数据存储好了,查询操作效率会比较高 ...
- asp.net core 二 Nginx Supervisor 负载,监听
ASP.NET Core负载均衡集群搭建(CentOS7+Nginx+Supervisor+Kestrel) asp.net core在linux运行下,一但命令行退出 ...
- JS查找字符串中出现次数最多的字符
本文给大家带来两种js中查找字符串中出现次数最多的字符,在这两种方法中小编推荐使用第二种,对js查找字符串出现次数的相关知识感兴趣的朋友一起看看吧 在一个字符串中,如 'zhaochucichuz ...