Linux文件误删除debugfs恢复操作

简介:

前言

作为一个多用户、多任务的操作系统,Linux下的文件一旦被删除,是难以恢复的。尽管删除命令只是在文件节点中作删除标记,并不真正清除文件内容,但是其他用户和一些有写盘动作的进程会很快覆盖这些数据。不过,对于家庭单机使用的Linux,或者误删文件后及时补救,还是可以恢复的


一、用运SecureCRT远程对操作系统上,查看一下当前系统版本号,及文件系统格式

[root@centos6 ~]# cat /etc/redhat-release 

CentOS release 6.8 (Final)

[root@centos6 ~]# cat /proc/version

Linux version 2.6.32-642.el6.x86_64 (mockbuild@worker1.bsys.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) ) #1 SMP Tue May 10 17:27:01 UTC 2016

[root@centos6 ~]# uname -a

Linux centos6 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@centos6 ~]# uname -r

2.6.32-642.el6.x86_64


二、为方便本次实验,我们新创建一文件。

[root@centos6 ~]# mkdir /example

[root@centos6 ~]# cd /example/

[root@centos6 example]# cat /proc/meminfo > web.txt

[root@centos6 example]# ll

total 4

-rw-r--r--. 1 root root 1198 Dec 25 05:35 web.txt


[root@centos6 example]# df /example/

Filesystem           1K-blocks    Used Available Use% Mounted on

/dev/mapper/vg_centos6-LogVol01

                      18971088 3484148  14516600  20% /

[root@centos6 example]# debugfs

debugfs 1.41.12 (17-May-2010)

debugfs:  open /dev/mapper/vg_centos6-LogVol01

debugfs:  ls -d /example/

 391720  (12) .    2  (12) ..    393297  (4072) web.txt   

debugfs:  quit


三、执行删除操作

[root@centos6 example]# rm -rf web.txt


四、打开,刚刚被删除文件所在的分区

[root@centos6 example]# df /example/

Filesystem           1K-blocks    Used Available Use% Mounted on

/dev/mapper/vg_centos6-LogVol01

                      18971088 3484148  14516600  20% /



五、用ls 加-d参数显示刚刚删除文件所在的目录

[root@centos6 example]# debugfs

debugfs 1.41.12 (17-May-2010)

debugfs:  open /dev/mapper/vg_centos6-LogVol01

debugfs:  ls -d /example/

 391720  (12) .    2  (4084) ..   <393297> (4072) web.txt  


六、显示有<>尖括号的就是我们要找的文件Inode 号 执行logdump –I  <19662057> 

debugfs:  logdump -i <393297>

Inode 393297 is at group 48, block 1572970, offset 2048

Journal starts at block 1, transaction 1746

No magic number at block 435: end of journal.

debugfs:  quit


七,执行完命令后,显示了一屏信息,我们需要的是下面这一行,并且要记住,后面的值

No magic number at block 435: end of journal.

debugfs:  quit


九、退出dedugfs

qiut



十,执行如下命令


[root@centos6 example]# dd if=/dev/mapper/vg_centos6-LogVol01 of=/example/web.txt bs=2048 count=1 skip=1572970

1+0 records in

1+0 records out

2048 bytes (2.0 kB) copied, 0.00769495 s, 266 kB/s




十一,以上结果表示恢复成功我们看下/example目录下到底有没有

[root@centos6 example]# ll /example/

total 4

-rw-r--r--. 1 root root 2048 Dec 25 05:52 web.txt




————————————————————————————————————————————————————————

centos7不管用

一、用运SecureCRT远程对操作系统上,查看一下当前系统版本号,及文件系统格式

[root@sheng ~]# cat /etc/redhat-release 

CentOS Linux release 7.4.1708 (Core) 

[root@sheng ~]# cat /proc/version

Linux version 3.10.0-693.5.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Fri Oct 20 20:32:50 UTC 2017

[root@sheng ~]# uname -a

Linux sheng 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[root@sheng ~]# uname -r

二、为方便本次实验,我们新创建一文件。

[root@sheng ~]# mkdir example

[root@sheng ~]# cd example/

[root@sheng example]# cat /proc/meminfo > web.txt

[root@sheng example]# ll

total 4

-rw-r--r--. 1 root root 1226 Dec 25 10:03 web.txt

[root@sheng example]# ls

web.txt

三、执行删除操作

[root@sheng example]# rm -rf web.txt 


四、打开,刚刚被删除文件所在的分区

*****************************************************************************************

查看目录在分区

[root@sheng example]# df /root/example

Filesystem          1K-blocks     Used Available Use% Mounted on

/dev/mapper/cl-root  18855936 11376924   7479012  61% /

******************************************************************************************

四、运用,系统自还工具debugfs来修复

[root@sheng example]# debugfs

debugfs 1.42.9 (28-Dec-2013)

debugfs:  open /dev/mapper/cl-root

/dev/mapper/cl-root: Bad magic number in super-block while opening filesystem


[root@sheng example]# df -Th

Filesystem          Type      Size  Used Avail Use% Mounted on

/dev/mapper/cl-root xfs        18G   11G  7.2G  61% /

.....

不支持xfs文件格式的恢复


CentOS7使用Extundelete恢复误删除的文件


本文转自 Mr_sheng 51CTO博客,原文链接:http://blog.51cto.com/sf1314/2054166


目录
打赏
0
0
0
0
344
分享
相关文章
|
19天前
|
Linux基础:文件和目录类命令分析。
总的来说,这些基础命令,像是Linux中藏匿的小矮人,每一次我们使用他们,他们就把我们的指令准确的传递给Linux,让我们的指令变为现实。所以,现在就开始你的Linux之旅,挥动你的命令之剑,探索这个充满神秘而又奇妙的世界吧!
63 19
|
1月前
|
Linux 常用文件查看命令
`cat` 命令用于连接文件并打印到标准输出,适用于快速查看和合并文本文件内容。常用示例包括:`cat file1.txt` 查看单个文件,`cat file1.txt file2.txt` 合并多个文件,`cat &gt; filename` 创建新文件,`cat &gt;&gt; filename` 追加内容。`more` 和 `less` 命令用于分页查看文件,`tail` 命令则用于查看文件末尾内容,支持实时追踪日志更新,如 `tail -f file.log`。
56 5
Linux 常用文件查看命令
|
13天前
|
如何创建Linux交换文件?Linux交换文件最新创建方法
Swap是Linux中的虚拟内存空间,用于在物理内存不足时将非活动进程移至磁盘,从而优化活动进程的性能。通过创建交换文件(如1GB),可灵活调整交换空间而无需重新分区。步骤包括:使用`fallocate`或`dd`创建文件、设置权限 (`chmod 600`)、格式化 (`mkswap`)、启用交换 (`swapon`)、修改`/etc/fstab`以持久化配置,以及调整`vm.swappiness`值(默认60,建议从10开始)来平衡内存与交换的使用。最后通过`swapon -s`检查状态并重启生效。此方法适用于VPS和专用服务器,需以root用户操作。
39 2
Linux|Transfer.sh 轻松实现文件共享
Linux|Transfer.sh 轻松实现文件共享
43 2
Linux|Transfer.sh 轻松实现文件共享
【Linux】进程IO|系统调用|open|write|文件描述符fd|封装|理解一切皆文件
本文详细介绍了Linux中的进程IO与系统调用,包括 `open`、`write`、`read`和 `close`函数及其用法,解释了文件描述符(fd)的概念,并深入探讨了Linux中的“一切皆文件”思想。这种设计极大地简化了系统编程,使得处理不同类型的IO设备变得更加一致和简单。通过本文的学习,您应该能够更好地理解和应用Linux中的进程IO操作,提高系统编程的效率和能力。
114 34
linux怎么把文件传到docker里面
在现代应用开发中,Docker作为流行的虚拟化工具,广泛应用于微服务架构。文件传输到Docker容器是常见需求。常用方法包括:1) `docker cp`命令直接复制文件;2) 使用`-v`选项挂载宿主机目录,实现数据持久化和实时同步;3) 通过SCP/FTP协议传输文件;4) 在Dockerfile中构建镜像时添加文件。选择合适的方法并确保网络安全是关键。
162 1
|
2月前
|
Linux文件与目录的日常
目录的切换 一般使用(”pwd“)显示当前所在的目录 比如:当前目录是在home下面的,与用户名相同的文件夹,可以使用(”cd“)命令来切换目录; 进入下载目录(”cd home/a/下载“)这种从给目录开头的一长串路经”叫做绝对路径“; 进入图片目录(”cd .. /图片/“)".."代表当前路径的上级路径,相对于当前的目录而言的”叫做相对路径“,(”.“)代表当前路径; 如果,想快速切换,上一个所在目录可以(”cd - / cd..“); 如果,想快速切换,追原始的目录可以(”cd --“); 查看目录及文件
55 14
|
2月前
|
Linux 将所有文件和目录名重命名为小写
Linux 将所有文件和目录名重命名为小写
55 3
Kali Linux系统Metasploit框架利用 HTA 文件进行渗透测试实验
本指南介绍如何利用 HTA 文件和 Metasploit 框架进行渗透测试。通过创建反向 shell、生成 HTA 文件、设置 HTTP 服务器和发送文件,最终实现对目标系统的控制。适用于教育目的,需合法授权。
129 9
Kali Linux系统Metasploit框架利用 HTA 文件进行渗透测试实验
|
4月前
|
golang编译成Linux可运行文件
本文介绍了如何在 Linux 上编译和运行 Golang 程序,涵盖了本地编译和交叉编译的步骤。通过这些步骤,您可以轻松地将 Golang 程序编译成适合 Linux 平台的可执行文件,并在目标服务器上运行。掌握这些技巧,可以提高开发和部署 Golang 应用的效率。
524 14
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等