Linux中误删文件如何恢复(Foremost安装使用)

本文介绍了 Linux中误删文件如何恢复,Foremost安装使用

在日常的系统操作,请小心的你文件,但是,如果您意识到您不小心删除了系统中的文件并且惊慌失措,别担心,此工具会轻松帮你找回误删除的文件!

这里介绍一款工具 Foremost

Foremost安装

CentOS/RHEL 7,是目前在生产环境见到的使用最广泛的版本,下面展示在CentOS/RHEL 7中的安装过程。

#rpm -Uvh https://rpmfind.net/linux/dag/redhat/el7/en/x86_64/dag/RPMS/foremost-1.5.7-1.el7.rf.x86_64.rpm

命令参数查看

[root@192_168_209_128 images]# foremost  -h
foremost version 1.5.7 by Jesse Kornblum, Kris Kendall, and Nick Mikus.
$ foremost [-v|-V|-h|-T|-Q|-q|-a|-w-d] [-t <type>] [-s <blocks>] [-k <size>] 
 
        [-b <size>] [-c <file>] [-o <dir>] [-i <file] 
-V  - display copyright information and exit
-t  - specify file type.  (-t jpeg,pdf ...) 
-d  - turn on indirect block detection (for UNIX file-systems) 
-i  - specify input file (default is stdin) 
-a  - Write all headers, perform no error detection (corrupted files) 
-w  - Only write the audit file, do not write any detected files to the disk 
-o  - set output directory (defaults to output)
-c  - set configuration file to use (defaults to foremost.conf)
-q  - enables quick mode. Search are performed on 512 byte boundaries.
-Q  - enables quiet mode. Suppress output messages. 
-v  - verbose mode. Logs all messages to screen

选项释义:

-t:指定要恢复的文件类型如jpeg,pdf,exe,doc等,如果要恢复所有文件类似,指定参数值为"all"即可。
-d:打开间接块检测(对于 UNIX 文件系统)。
-i:指定输入文件(默认为标准输入)。
-a:不执行错误检测(损坏的文件)。
-w:只输出审计文件,不输出被删除的文件至磁盘上。
-o:设置输出目录(默认为输出)。

文件恢复测试

(1) 安装完成后,让我们进行一个简单的测试。

首先我们将xihu.jpg从/boot/images目录中删除:

[root@192_168_209_128 images]# cd image
[root@192_168_209_128 images]# pwd
/boot/images
[root@192_168_209_128 images]# ls
xihu.jpg
[root@192_168_209_128 images]# rm xihu.jpg

(2) 执行恢复。

要恢复它,首先按如下方式使用(您需要首先识别底层分区 -在这种情况下/dev/sda1就是/boot所在的分区):

remost -t jpg -i /dev/sda1 -o /home/rescure/

(3) 查看恢复情况。

查看一下审计文件。

查看恢复文件

从输出内容来看,文件被成功恢复。

注意事项:

  • 其中/home/rescue是单独磁盘上的目录 - 请记住,在已删除文件所在的同一驱动器上恢复文件不是明智之举。
  • 如果在恢复过程中,您占用已删除文件所在的相同磁盘扇区,则可能无法恢复任何内容。此外,必须在执行恢复之前停止所有活动。
  • 在 foremost 完成执行后,恢复的文件(如果可以恢复)将在/home/rescue/jpg目录中找到。
上一篇 下一篇


推荐文章

评论
说点什么吧?

发表评论

取消回复
  最新文章