首页 > 编程知识 正文

ubuntu误删除文件怎么还原,删除文件 ubuntu

时间:2023-05-06 02:12:27 阅读:180852 作者:741

Ubuntu恢复被删除的文件

昨天不小心,运行了rm xx -rf,删除了一个项目。 还有各种后悔,各种自责,这个项目一周的工作量啊。 最后一定要解决,所以通过谷歌搜索找到了恢复神器extundelete,最后顺利恢复了我无意中删除的所有文件。 感谢上天,感谢extundelete。 以下总结个人经验。

extundelete的使用方法

1 )下载工具extundelete

在Ubuntu下载这个工具很简单

33558 www.Sina.com/viewplaincopysudoapt-getinstallextundelete

2 )使用

使用这个也很简单。 ext undeletehelp命令可以告诉您很多事情。

3358 www.Sina.com/viewplaincopyitleaks @ it leaks 3360:~$ ext undelete-- help usage 3360 ext undelete [-options ] evice-file options :……………--- afterdtimeonlyprocessentriesdeletedonorafter ' dtime '.--beforedtimeonlypronlyprocesprocestice path '.' path ' isrelativetorootofthepartitionanddoesnotstartwitha '/' (.therestoredfileiscreatedinthecurrentdirectoryas path '.--restore-files ' path ' willrestorefileswhicharelistedinthefile ' path '.eachfilenameshouldbeinthesameformatasmeformatastastasth Shi andthereshouldbeoneperline.--- output-dir ' path ' restorefilesintheoutputdir ' path '.bydefaulttherestoredfilesath reat dir.--restore-allattemptstorestoreeverything………………我们在无意中删除了有用的文件时,一般比较容易知道删除的时间,所以使用时间是option 那么,这个dtime怎么生成? 请参阅以下命令:

3358 www.Sina.com/viewplaincopyitleaks @ it leaks :~$ date-d ' 2014-06-012:0236000 ' % s 1401634920 % s的

你可以用这个来恢复

3358 www.Sina.com/viewplaincopysudoextundelete/dev/SD A8---- after 1401634920---restore-all在此进行实验。 具体操作如下

3358 www.Sina.com/viewplaincopyitleaks @ it leaks :/tmp

$ echo "recovery test"> itleaks.test  Itleaks@ Itleaks:/tmp$ rm itleaks.test   Itleaks@ Itleaks:/tmp$ date -d "2014-06-01 22:28:00" +%s  1401632880  Itleaks@ Itleaks:/tmp$ sudo extundelete /dev/sda8 --after 1401632880 --restore-all  Only show and process deleted entries if they are deleted on or after 1401632880 and before 9223372036854775807.    WARNING: Extended attributes are not restored.  WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set.  The partition should be unmounted to undelete any files without further data loss.  If the partition is not currently mounted, this message indicates   it was improperly unmounted, and you should run fsck before continuing.  If you decide to continue, extundelete may overwrite some of the deleted  files and make recovering those files impossible.  You should unmount the  file system and check it with fsck before using extundelete.  Would you like to continue? (y/n)   y  Loading filesystem metadata ... 378 groups loaded.  Loading journal descriptors ...   27106 descriptors loaded.  Searching for recoverable inodes in directory / ...     85 recoverable inodes found.  Looking through the directory structure for deleted files ...   ………………..  Unable to restore inode 2360218 (etc/brltty/brl-fs-bumpers.kti): No undeleted copies found in the journal.  Unable to restore inode 2359564 (etc/mtab~): No undeleted copies found in the journal.  Restored inode 2883641 to file RECOVERED_FILES/tmp/itleaks.test    Itleaks@ Itleaks:/tmp$ tree RECOVERED_FILES/  RECOVERED_FILES/  └── tmp      └── itleaks.test    1 directory, 1 file   extundelete原理

         这个是由于linuxext3文件系统的组织结构决定的,如下图:

          

         在Linux系统中,超级块描述了分区的信息,一个分区被分为两个部分,索引节点表和数据块区,这个在格式化的时候就定下来了。文件(目录也是文件的一种,只不过它的内容是描述目录下的文件的)由索引节点描述,索引节点描述了文件的修改时间,文件的名称,文件的数据块地址等等。并且,linux对于文件删除操作是个懒动作,删除文件时系统只是将文件对应的索引节点及其拥有的数据块置为free(将nlink=0),而并没有做其他清空的,只有当这个索引节点或者数据块被真正用到的时候才会修改里面的数据。这就为我们文件修复提供了可趁之机。由于系统中的索引节点是固定大小的,因此可以很轻松的遍历扫描系统中所有的索引节点,找出free的索引节点并检查其数据块是否已经被用,如果没有则可修复并修复。同时,由于索引节点里的时间等信息也是保留的,因此就可以根据时间来恢复特定的被删除的文件。

文件误删除后的注意事项

     从上面的分析可知,误删文件后,尽量不要做大的数据操作,以避免被删除的文件的数据块被重新使用,导致数据完全丢失。


/********************************

* 本文来自博客  “爱踢门”

* 转载请标明出处:http://blog.csdn.net/itleaks

******************************************/


版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。