当前位置: 首页 > 编程文章 >

Linux环境下恢复rm误删文件的方法与预防

Linux环境下恢复rm误删文件的方法与预防

作者:周澄时间:2026-02-15 14:40:08浏览:793

在Linux系统中执行rm命令会导致文件永久删除,但通过及时干预仍有机会恢复。本文介绍使用foremost和extundelete两款工具进行文件恢复的具体步骤、参数及注意事项,并对比两者适用场景。同时提供定义别名和使用mv替代rm等预防误删的有效方法,帮助降低数据丢失风险。

本文目录展开

前言

提及Linux环境下的文件删除操作,sudo rm -rf /* 这一命令常被视为经典“梗”,每次看到它,脑海中总会浮现出那张广为流传的恶搞图片:

rm

该图片中关于‘清理垃圾’的描述可谓精准到位。传闻曾有新手在论坛求助,被他人戏谑地回复了 sudo rm -rf /* 指令,结果不仅问题得以‘解决’,用户账号也彻底消失~

从‘删库跑路’到每日新增一种‘入狱技巧’,我们必须对 rm -rf 命令保持极度谨慎。这类似于Windows系统中的 Shift+Delete 组合键,文件不会进入回收站,而是直接永久移除。在Linux中执行 rm 即意味着不可逆的删除操作。

尽管 sudo rm -rf /* 极具危险性,但我们通常不会直接这样输入。然而,常规的 rm 命令使用频率极高。就在前几天,我辛苦编写的Shell脚本便因误操作被 rm -rf 删除。幸好此前已将内容输出至控制台,否则心血将付诸东流。

rm之后还有救吗

虽然 rm 命令旨在永久删除,但这并不意味着文件必然无法找回,只是成功率存在差异。删除操作本质上是在文件节点中标记删除,并未立即清除磁盘上的实际数据。若在删除后迅速进行恢复尝试,成功率较高;但若其他用户持续使用机器或有进程不断写入磁盘,数据可能很快被覆盖,此时恢复基本无望。

使用foremost找回文件

foremost 是一款基于文件头尾信息及内建数据结构来恢复文件的命令行工具。以下是其安装与恢复操作的详细步骤:

安装 foremost

在CentOS系统中,可直接运行 sudo yum install https://forensics.cert.org/centos/cert/7/x86_64//foremost-1.5.7-13.1.el7.x86_64.rpm -y 命令完成安装。

若使用Ubuntu系统,请尝试执行以下命令:sudo apt install foremost


[root@VM-0-3-centos ~]# sudo yum install https://forensics.cert.org/centos/cert/7/x86_64//foremost-1.5.7-13.1.el7.x86_64.rpm -y
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
foremost-1.5.7-13.1.el7.x86_64.rpm                                                     |  46 kB  00:00:01
Examining /var/tmp/yum-root-XJIfxM/foremost-1.5.7-13.1.el7.x86_64.rpm: foremost-1.5.7-13.1.el7.x86_64
Marking /var/tmp/yum-root-XJIfxM/foremost-1.5.7-13.1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package foremost.x86_64 0:1.5.7-13.1.el7 will be installed
--> Finished Dependency Resolution
epel/7/x86_64                                                                          | 4.7 kB  00:00:00
epel/7/x86_64/group_gz                                                                 |  96 kB  00:00:00
epel/7/x86_64/updateinfo                                                               | 1.0 MB  00:00:00
epel/7/x86_64/primary_db                                                               | 7.0 MB  00:00:01
extras/7/x86_64                                                                        | 2.9 kB  00:00:00
extras/7/x86_64/primary_db                                                             | 243 kB  00:00:00
os/7/x86_64                                                                            | 3.6 kB  00:00:00
updates/7/x86_64                                                                       | 2.9 kB  00:00:00
updates/7/x86_64/primary_db                                                            |  12 MB  00:00:01

Dependencies Resolved

=====================================================================================================================
 Package                    Arch                 Version                 Repository                           Size
=====================================================================================================================
Installing:
 foremost                  x86_64           1.5.7-13.1.el7           /foremost-1.5.7-13.1.el7.x86_64          85 k

Transaction Summary
=====================================================================================================================
Install  1 Package

Total size: 85 k
Installed size: 85 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : foremost-1.5.7-13.1.el7.x86_64                                                1/1
  Verifying  : foremost-1.5.7-13.1.el7.x86_64                                                1/1

Installed:
  foremost.x86_64 0:1.5.7-13.1.el7

Complete!
[root@VM-0-3-centos ~]#

创建一个测试文件


[root@VM-0-3-centos ~]# echo "this is a important file">important.txt
[root@VM-0-3-centos ~]# pwd
/root
[root@VM-0-3-centos ~]# ls
connecttendis.sh  important.txt  restore  tarlist  tendis  test.iso
[root@VM-0-3-centos ~]# mkdir -p /tmp/restore

删除文件后尝试还原


[root@VM-0-3-centos ~]# rm important.txt
[root@VM-0-3-centos ~]# foremost -i /dev/vda1 -o /tmp/restore/
Processing: /dev/vda1
|***********Segmentation fault

执行数分钟后程序崩溃,恢复失败。打开目标目录查看,发现如下情况:


[root@VM-0-3-centos ~]# ls /tmp/restore/
audit.txt  bmp  doc   exe  htm  jpg  mov  mpg  pdf  ppt   rar  sdw  sxc  sxw  wav  xls   zip
avi        dll  docx  gif  jar  mbd  mp4  ole  png  pptx  rif  sx   sxi  vis  wmv  xlsx

这表明恢复效果可能与文件类型相关。更换一台机器并选择png格式文件进行测试,先准备一个名为 showball.png 的测试文件,随后确认分区为 /dev/vda1。


[root@VM-0-3-centos ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          930496       0    930496   0% /dev
tmpfs             941004      24    940980   1% /dev/shm
tmpfs             941004     508    940496   1% /run
tmpfs             941004       0    941004   0% /sys/fs/cgroup
/dev/vda1       51473868 6458344  42692404  14% /
/dev/loop0        361650  361650         0 100% /mnt/iso
tmpfs             188204       0    188204   0% /run/user/0
[root@VM-0-3-centos ~]# pwd
/root
[root@VM-0-3-centos ~]# ls
restore  showball.png

删除png文件后尝试恢复,待进度条结束后,即可进入指定目录 /root/restore/ 进行查看。


[root@VM-0-3-centos ~]# rm showball.png
rm: remove regular file ‘showball.png'? y
[root@VM-0-3-centos ~]# pwd
/root
[root@VM-0-3-centos ~]# foremost -t png -i /dev/vda1 -o /root/restore/
Processing: /dev/vda1
|*********************************************************************************************|

在指定目录下会生成一个 audit.txt 统计文件以及一个按类型命名的文件夹 png。


[root@VM-0-3-centos ~]# ll restore/
total 40
-rw-r--r-- 1 root root 24548 Nov 27 22:57 audit.txt
drwxr-xr-- 2 root root 16384 Nov 27 22:56 png
[root@VM-0-3-centos ~]# cd restore/
[root@VM-0-3-centos restore]# ll png
total 43764
-rw-r--r-- 1 root root    3500 Nov 27 22:53 00367400.png
-rw-r--r-- 1 root root    3578 Nov 27 22:53 00367408.png
-rw-r--r-- 1 root root    3445 Nov 27 22:53 00367416.png
-rw-r--r-- 1 root root     368 Nov 27 22:53 00367432.png
-rw-r--r-- 1 root root     363 Nov 27 22:53 00367456.png
-rw-r--r-- 1 root root     392 Nov 27 22:53 00367464.png
-rw-r--r-- 1 root root     199 Nov 27 22:53 00367616.png
...

png目录下的文件名均为随机编号,与原文件名完全不同,需依据 audit.txt 文件进行确认。打开该文件查看详情:


[root@VM-0-3-centos restore]# head audit.txt
Foremost version 1.5.7 by Jesse Kornblum, Kris Kendall, and Nick Mikus
Audit File

Foremost started at Sat Nov 27 22:53:48 2026
Invocation: foremost -t png -i /dev/vda1 -o /root/restore/
Output directory: /root/restore
Configuration file: /etc/foremost.conf
------------------------------------------------------------------
File: /dev/vda1
Start: Sat Nov 27 22:53:48 2026
[root@VM-0-3-centos restore]# head -n 20 audit.txt
Foremost version 1.5.7 by Jesse Kornblum, Kris Kendall, and Nick Mikus
Audit File

Foremost started at Sat Nov 27 22:53:48 2026
Invocation: foremost -t png -i /dev/vda1 -o /root/restore/
Output directory: /root/restore
Configuration file: /etc/foremost.conf
------------------------------------------------------------------
File: /dev/vda1
Start: Sat Nov 27 22:53:48 2026
Length: 49 GB (53686025728 bytes)

Num  Name (bs=512)         Size  File Offset     Comment

0:  00367400.png           3 KB       188108800       (16 x 16)
1:  00367408.png           3 KB       188112896       (16 x 16)
2:  00367416.png           3 KB       188116992       (16 x 16)
3:  00367432.png          368 B       188125184       (16 x 16)
4:  00367456.png          363 B       188137472       (16 x 16)
5:  00367464.png          392 B       188141568       (16 x 16)
...

audit.txt 记录了恢复文件的简要信息。这需要你事先知晓原文件的相关信息,否则只能逐一打开检查。我是通过分辨率筛选来定位的。


[root@VM-0-3-centos restore]# grep "1217" audit.txt
116:    12888200.png          40 KB      6598758400       (1217 x 690)
360:    38088960.png          40 KB      19501547520      (1217 x 690)

根据过滤出的信息,打开 12888200.png 确认,发现正是之前“误删”的文件,至此恢复成功。

使用extundelete找回文件

extundelete 支持对ext3、ext4文件系统下的文件进行恢复。可通过 cat /etc/fstab 命令在Linux环境下查看当前文件系统类型。


[root@VM-0-3-centos ~]# cat /etc/fstab
UUID=21dbe030-aa71-4b3a-8610-3b942dd447fa            /                    ext4       noatime,acl,user_xattr 1 1
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
[root@VM-0-3-centos ~]#

安装依赖文件


[root@VM-0-3-centos ~]# yum install e2fsprogs-devel
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Determining fastest mirrors
epel                                                                                  | 4.7 kB  00:00:00
extras                                                                                | 2.9 kB  00:00:00
os                                                                                    | 3.6 kB  00:00:00
updates                                                                               | 2.9 kB  00:00:00
(1/2): epel/7/x86_64/updateinfo                                                       | 1.0 MB  00:00:00
(2/2): epel/7/x86_64/primary_db                                                       | 7.0 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package e2fsprogs-devel.x86_64 0:1.42.9-19.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================
 Package                 Arch                     Version                       Repository          Size
===============================================================================================================
Installing:
 e2fsprogs-devel        x86_64                    1.42.9-19.el7                     os              73 k

Transaction Summary
===============================================================================================================
Install  1 Package

Total download size: 73 k
Installed size: 162 k
Is this ok [y/d/N]: y
Downloading packages:
e2fsprogs-devel-1.42.9-19.el7.x86_64.rpm                                              |  73 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : e2fsprogs-devel-1.42.9-19.el7.x86_64                                  1/1
  Verifying  : e2fsprogs-devel-1.42.9-19.el7.x86_64                                  1/1

Installed:
  e2fsprogs-devel.x86_64 0:1.42.9-19.el7

Complete!
[root@VM-0-3-centos ~]#

下载extundelete源码包


[root@VM-0-3-centos ~]# wget https://src.fedoraproject.org/repo/pkgs/extundelete/extundelete-0.2.4.tar.bz2/77e626ad31433680c0a222069295d2ca/extundelete-0.2.4.tar.bz2
--2026-11-28 18:36:15--  https://src.fedoraproject.org/repo/pkgs/extundelete/extundelete-0.2.4.tar.bz2/77e626ad31433680c0a222069295d2ca/extundelete-0.2.4.tar.bz2
Resolving src.fedoraproject.org (src.fedoraproject.org)... 38.145.60.20, 38.145.60.21
Connecting to src.fedoraproject.org (src.fedoraproject.org)|38.145.60.20|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 108472 (106K) [application/x-bzip2]
Saving to: ‘extundelete-0.2.4.tar.bz2'

100%[============================================================================>] 108,472     33.5KB/s   in 3.2s

2026-11-28 18:36:20 (33.5 KB/s) - ‘extundelete-0.2.4.tar.bz2' saved [108472/108472]

[root@VM-0-3-centos ~]# ls
extundelete-0.2.4.tar.bz2

解压extundelete源码包


[root@VM-0-3-centos ~]# tar -jxvf extundelete-0.2.4.tar.bz2
extundelete-0.2.4/
extundelete-0.2.4/acinclude.m4
extundelete-0.2.4/missing
extundelete-0.2.4/autogen.sh
extundelete-0.2.4/aclocal.m4
extundelete-0.2.4/configure
extundelete-0.2.4/LICENSE
extundelete-0.2.4/README
extundelete-0.2.4/install-sh
extundelete-0.2.4/config.h.in
extundelete-0.2.4/src/
extundelete-0.2.4/src/extundelete.cc
extundelete-0.2.4/src/block.h
extundelete-0.2.4/src/kernel-jbd.h
extundelete-0.2.4/src/insertionops.cc
extundelete-0.2.4/src/block.c
extundelete-0.2.4/src/cli.cc
extundelete-0.2.4/src/extundelete-priv.h
extundelete-0.2.4/src/extundelete.h
extundelete-0.2.4/src/jfs_compat.h
extundelete-0.2.4/src/Makefile.in
extundelete-0.2.4/src/Makefile.am
extundelete-0.2.4/configure.ac
extundelete-0.2.4/depcomp
extundelete-0.2.4/Makefile.in
extundelete-0.2.4/Makefile.am
[root@VM-0-3-centos ~]# cd extundelete-0.2.4/
[root@VM-0-3-centos extundelete-0.2.4]# ls
acinclude.m4  aclocal.m4  autogen.sh   config.h.in  configure  configure.ac  depcomp
install-sh    LICENSE     Makefile.am  Makefile.in  missing    README        src
[root@VM-0-3-centos extundelete-0.2.4]#

编译xtundelete源码并完成安装


[root@VM-0-3-centos extundelete-0.2.4]# ./configure --prefix=/usr/local/extundelete && make && make install
Configuring extundelete 0.2.4
Writing generated files to disk
make -s all-recursive
Making all in src
extundelete.cc: In function ‘ext2_ino_t find_inode(ext2_filsys, ext2_filsys, ext2_inode*, std::string, int)':
extundelete.cc:1272:29: warning: narrowing conversion of ‘search_flags' from ‘int' to ‘ext2_ino_t {aka unsigned int}' inside { } [-Wnarrowing]
    buf, match_name2, priv, 0};
                             ^
Making install in src
  /usr/bin/install -c extundelete '/usr/local/extundelete/bin'
[root@VM-0-3-centos extundelete-0.2.4]# which extundelete
/usr/bin/which: no extundelete in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@VM-0-3-centos extundelete-0.2.4]# ll /usr/local/extundelete/bin/
total 1296
-rwxr-xr-x 1 root root 1323360 Nov 28 18:45 extundelete

若在此步骤遇到报错 configure: error: C++ compiler cannot create executables,可运行 yum -y install gcc-c++ 命令以安装必要的编译环境。

准备测试文件


[root@VM-0-3-centos examples]# df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
devtmpfs       devtmpfs    930496       0    930496   0% /dev
tmpfs          tmpfs       941004      24    940980   1% /dev/shm
tmpfs          tmpfs       941004     508    940496   1% /run
tmpfs          tmpfs       941004       0    941004   0% /sys/fs/cgroup
/dev/vda1      ext4      51473868 6465732  42685016  14% /
/dev/loop0     iso9660     361650  361650         0 100% /mnt/iso
tmpfs          tmpfs       188204       0    188204   0% /run/user/0
[root@VM-0-3-centos examples]# cp ../extundelete-0.2.4.tar.bz2 .
[root@VM-0-3-centos examples]# ls
extundelete-0.2.4.tar.bz2

查询文件的inode信息

我们选取刚下载的extundelete源码包作为“误删”对象,先查看其详细信息。-li 选项可在第一列显示文件的inode信息,其中examples文件夹的inode值为1311798:


[root@VM-0-3-centos ~]# ls examples/
extundelete-0.2.4.tar.bz2
[root@VM-0-3-centos ~]# ls -li
total 361676
1311798 drwxr-xr-x 2 root root      4096 Nov 28 20:28 examples
1310761 drwxr-xr-x 3 1000 1000      4096 Nov 28 18:45 extundelete-0.2.4
 918157 drwxr-xr-x 2 root root      4096 Feb 28  2026 tarlist
 396057 -rw-r--r-- 1 root root 370329600 Feb 27  2026 test.iso

删除测试文件,并用查询信息


[root@VM-0-3-centos ~]# cd examples/
[root@VM-0-3-centos examples]# ls
extundelete-0.2.4.tar.bz2
[root@VM-0-3-centos examples]# rm extundelete-0.2.4.tar.bz2 -f
[root@VM-0-3-centos examples]# ls
[root@VM-0-3-centos examples]# /usr/local/extundelete/bin/extundelete /dev/vda1 --inode 1311798
NOTICE: 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 ... 400 groups loaded.
Group: 160
Contents of inode 1311798:
0000 | ed 41 00 00 00 10 00 00 7a 62 a3 61 1b 7a a3 61 | .A......zb.a.z.a
0010 | 1b 7a a3 61 00 00 00 00 00 00 02 00 08 00 00 00 | .z.a............
0020 | 00 00 08 00 0b 00 00 00 0a f3 01 00 04 00 00 00 | ................
0030 | 00 00 00 00 00 00 00 00 01 00 00 00 79 20 50 00 | ............y P.
0040 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0050 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0060 | 00 00 00 00 7c 63 ab ad 00 00 00 00 00 00 00 00 | ....|c..........
0070 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
0080 | 1c 00 00 00 80 da 0d a3 80 da 0d a3 94 24 04 08 | .............$..
0090 | 7a 62 a3 61 94 24 04 08 00 00 00 00 00 00 00 00 | zb.a.$..........
00a0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00b0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00c0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00d0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00e0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................
00f0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................

Inode is Allocated
File mode: 16877
Low 16 bits of Owner Uid: 0
Size in bytes: 4096
Access time: 1638097530
Creation time: 1638103579
Modification time: 1638103579
Deletion Time: 0
Low 16 bits of Group Id: 0
Links count: 2
Blocks count: 8
File flags: 524288
File version (for NFS): 2913690492
File ACL: 0
Directory ACL: 0
Fragment address: 0
Direct blocks: 127754, 4, 0, 0, 1, 5251193, 0, 0, 0, 0, 0, 0
Indirect block: 0
Double indirect block: 0
Triple indirect block: 0

File name                                       | Inode number | Deleted status
.                                                 1311798
..                                                393219
extundelete-0.2.4.tar.bz2                         396764         Deleted
conftest.err                                      1311833        Deleted
[root@VM-0-3-centos examples]#

我们发现 extundelete-0.2.4.tar.bz2 文件的状态显示为 Deleted。

使用extundelete恢复文件


[root@VM-0-3-centos ~]# /usr/local/extundelete/bin/extundelete /dev/vda1 --restore-directory /tmp
NOTICE: 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 ... 400 groups loaded.
Loading journal descriptors ... 31842 descriptors loaded.
*** Error in `/usr/local/extundelete/bin/extundelete': double free or corruption (!prev): 0x00000000014d6020 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x81299)[0x7f5c08190299]
/usr/local/extundelete/bin/extundelete[0x40cdcb]
/usr/local/extundelete/bin/extundelete[0x40fee6]
/usr/local/extundelete/bin/extundelete[0x4045b4]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f5c08131555]
/usr/local/extundelete/bin/extundelete[0x404aef]
======= Memory map: ========
00400000-0041c000 r-xp 00000000 fd:01 1311942                            /usr/local/extundelete/bin/extundelete
0061c000-0061d000 r--p 0001c000 fd:01 1311942                            /usr/local/extundelete/bin/extundelete
0061d000-0061e000 rw-p 0001d000 fd:01 1311942                            /usr/local/extundelete/bin/extundelete
0061e000-0061f000 rw-p 00000000 00:00 0
014c6000-0176e000 rw-p 00000000 00:00 0                                  [heap]
7f5c00000000-7f5c00021000 rw-p 00000000 00:00 0
7f5c00021000-7f5c04000000 ---p 00000000 00:00 0
7f5c07ca1000-7f5c07ef3000 rw-p 00000000 00:00 0
7f5c07ef3000-7f5c07f0a000 r-xp 00000000 fd:01 265649                     /usr/lib64/libpthread-2.17.so
7f5c07f0a000-7f5c08109000 ---p 00017000 fd:01 265649                     /usr/lib64/libpthread-2.17.so
7f5c08109000-7f5c0810a000 r--p 00016000 fd:01 265649                     /usr/lib64/libpthread-2.17.so
7f5c0810a000-7f5c0810b000 rw-p 00017000 fd:01 265649                     /usr/lib64/libpthread-2.17.so
7f5c0810b000-7f5c0810f000 rw-p 00000000 00:00 0
7f5c0810f000-7f5c082d2000 r-xp 00000000 fd:01 265623                     /usr/lib64/libc-2.17.so
7f5c082d2000-7f5c084d2000 ---p 001c3000 fd:01 265623                     /usr/lib64/libc-2.17.so
7f5c084d2000-7f5c084d6000 r--p 001c3000 fd:01 265623                     /usr/lib64/libc-2.17.so
7f5c084d6000-7f5c084d8000 rw-p 001c7000 fd:01 265623                     /usr/lib64/libc-2.17.so
7f5c084d8000-7f5c084dd000 rw-p 00000000 00:00 0
7f5c084dd000-7f5c084f2000 r-xp 00000000 fd:01 291206                     /usr/lib64/libgcc_s-4.8.5-20260702.so.1
7f5c084f2000-7f5c086f1000 ---p 00015000 fd:01 291206                     /usr/lib64/libgcc_s-4.8.5-20260702.so.1
7f5c086f1000-7f5c086f2000 r--p 00014000 fd:01 291206                     /usr/lib64/libgcc_s-4.8.5-20260702.so.1
7f5c086f2000-7f5c086f3000 rw-p 00015000 fd:01 291206                     /usr/lib64/libgcc_s-4.8.5-20260702.so.1
7f5c086f3000-7f5c087f4000 r-xp 00000000 fd:01 287349                     /usr/lib64/libm-2.17.so
7f5c087f4000-7f5c089f3000 ---p 00101000 fd:01 287349                     /usr/lib64/libm-2.17.so
7f5c089f3000-7f5c089f4000 r--p 00100000 fd:01 287349                     /usr/lib64/libm-2.17.so
7f5c089f4000-7f5c089f5000 rw-p 00101000 fd:01 287349                     /usr/lib64/libm-2.17.so
7f5c089f5000-7f5c08ade000 r-xp 00000000 fd:01 266798                     /usr/lib64/libstdc++.so.6.0.19
7f5c08ade000-7f5c08cde000 ---p 000e9000 fd:01 266798                     /usr/lib64/libstdc++.so.6.0.19
7f5c08cde000-7f5c08ce6000 r--p 000e9000 fd:01 266798                     /usr/lib64/libstdc++.so.6.0.19
7f5c08ce6000-7f5c08ce8000 rw-p 000f1000 fd:01 266798                     /usr/lib64/libstdc++.so.6.0.19
7f5c08ce8000-7f5c08cfd000 rw-p 00000000 00:00 0
7f5c08cfd000-7f5c08d3f000 r-xp 00000000 fd:01 267873                     /usr/lib64/libext2fs.so.2.4
7f5c08d3f000-7f5c08f3f000 ---p 00042000 fd:01 267873                     /usr/lib64/libext2fs.so.2.4
7f5c08f3f000-7f5c08f40000 r--p 00042000 fd:01 267873                     /usr/lib64/libext2fs.so.2.4
7f5c08f40000-7f5c08f42000 rw-p 00043000 fd:01 267873                     /usr/lib64/libext2fs.so.2.4
7f5c08f42000-7f5c08f45000 r-xp 00000000 fd:01 265948                     /usr/lib64/libcom_err.so.2.1
7f5c08f45000-7f5c09144000 ---p 00003000 fd:01 265948                     /usr/lib64/libcom_err.so.2.1
7f5c09144000-7f5c09145000 r--p 00002000 fd:01 265948                     /usr/lib64/libcom_err.so.2.1
7f5c09145000-7f5c09146000 rw-p 00003000 fd:01 265948                     /usr/lib64/libcom_err.so.2.1
7f5c09146000-7f5c09168000 r-xp 00000000 fd:01 265614                     /usr/lib64/ld-2.17.so
7f5c092b1000-7f5c0935d000 rw-p 00000000 00:00 0
7f5c09363000-7f5c09367000 rw-p 00000000 00:00 0
7f5c09367000-7f5c09368000 r--p 00021000 fd:01 265614                     /usr/lib64/ld-2.17.so
7f5c09368000-7f5c09369000 rw-p 00022000 fd:01 265614                     /usr/lib64/ld-2.17.so
7f5c09369000-7f5c0936a000 rw-p 00000000 00:00 0
7ffe581db000-7ffe581fc000 rw-p 00000000 00:00 0                          [stack]
7ffe581fc000-7ffe581fe000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted
[root@VM-0-3-centos ~]#

恢复失败,此路不通!!!

虽有他人成功案例,但我测试未通过,释放内存时发生崩溃。若有大神知晓如何修改源码,敬请指教。此处暂存疑,后续再测,先记录常用参数。

查询inode文件状态:/usr/local/extundelete/bin/extundelete /dev/vda1 --inode 1311798

恢复指定节点数据:/usr/local/extundelete/bin/extundelete /dev/vda1 --restore-inode 1311798

恢复单个文件:/usr/local/extundelete/bin/extundelete /dev/vda1 --restore-file root/examples/extundelete-0.2.4.tar.bz2

恢复一个目录:/usr/local/extundelete/bin/extundelete /dev/vda1 --restore-files root/examples

恢复所有文件:/usr/local/extundelete/bin/extundelete /dev/vda1 --restore-all

预防误删引发的事故

定义别名,提示删除

定义别名 alias rm='rm -i',在删除文件前会出现提示。使用 -i 选项可逐个确认要删除的文件,只有用户输入 y 才会执行删除。但需注意,若加上 -f 选项,此保护机制将失效。

禁用rm,使用mv代替

在系统中禁止直接使用rm命令删除文件,而是将文件移动至指定的回收目录 /.delete。随后配合定时任务,每周清空 /.delete 下的文件,相当于手动构建了一个回收站机制。

总结

使用foremost恢复时,目标目录最好位于另一个磁盘中。若将文件恢复到被删除文件所在的磁盘,极有可能在恢复过程中覆盖尚未恢复的数据。

sodu 的全称目前主要有 substitute user do 和 super user do 两种说法。使用sudo通常是行使超级用户权限,但有时也可代表其他普通用户,因此翻译为 substitute user do 更为准确。

foremost 支持的文件系统较多,包括 ext2、ext3、vfat、NTFS、ufs、jfs 等,但仅能恢复特定格式的文件。而 extundelete 仅支持ext3、ext4文件系统,不过可恢复的文件类型更为丰富。

除本文介绍的这两款恢复软件外,testdisk 和 photorec 也是可用的恢复工具,后续可进一步尝试。数据无价,请务必谨慎删除,可参考别名设置或禁用 rm -rf 以减少事故发生。

到此这篇关于linux环境下恢复rm误删的文件方法的文章就介绍到这了,更多相关linux恢复rm误删的文件内容请搜索本站以前的文章或继续浏览下面的相关文章希望大家以后多多支持本站!

上一篇
CentOS 5.4 配置 yum 安装 Apache+PHP+MySQL

本文介绍在 CentOS 5.4 系统中通过 yum 源配置一键安装 Apache、PHP 和 MySQL 的方法。首先需替换中科大镜像源以解决依赖问题,随后执行更新及组件安装命令,最后完成服务自启动设置、数据库 root 密码配置及安全加固操作。

下一篇
重启宝塔面板报错ModuleNotFoundError: No module named 'geventwebsocket'的解决

在服务器部署Flask项目并安装Python 3后,重启宝塔面板时出现启动失败错误。Traceback显示缺失'geventwebsocket'模块,随后尝试安装又提示缺少'paramiko'。通过依次使用pip3安装这两个依赖包,最终成功恢复宝塔面板服务。

相关文章

更多
LINUX下PHP程序实现WORD文件转化为PDF文件的方法

本文介绍在LINUX环境下通过PHP程序将Word文件转换为PDF文件的具体实现方法。文中提供了相关的代码示例及参考链接,旨在帮助开发者解决文件格式转换需求,提升文档处理效率。

2026.11.12 1,000
Linux主机AMH管理面板安装与建站指南

AMH是一款独立的LNMP/Nginx虚拟主机管理面板,支持Centos、Debian和Ubuntu系统。本文介绍如何在纯净Linux系统中通过脚本安装AMH 4.2版本,包括设置MySQL和管理员密码。安装完成后,通过Web端配置虚拟主机、绑定域名、创建FTP账号及数据库,即可快速搭建网站。

2026.11.13 999
Linux内核container_of宏原理与实现解析

Linux内核中container_of宏用于通过结构体成员地址反推结构体首地址。其核心依赖于offsetof宏计算成员偏移量,利用( char *)ptr减去偏移量并强转为目标类型指针实现定位。该宏还包含类型检查机制以增强代码安全性。

2026.06.01 993
Linux、Windows 及源码安装 Git 完整指南

本文介绍在 Linux、Windows 系统及从源代码三个环境下安装 Git 的具体方法。Linux 用户可通过 yum 或 apt-get 使用包管理器快速部署;Windows 用户可选择官方 Git for Windows 安装包或 GitHub for Windows,后者提供图形界面与 PowerShell 支持;此外,文章还详细说明了通过编译源码获取最新版本的依赖库准备、下载及构建流程。

2026.06.03 991
Linux useradd 命令详解:群组与家目录配置实战

在 Linux 系统中,useradd 是用于创建或更新用户信息的底层命令。由于直接使用较为复杂,Debian 系发行版提供了 adduser 脚本作为简化封装。本文基于 Ubuntu14.04 环境,深入解析 useradd 在处理初始群组(-g/-G/-N)和家目录(-m/-d)时的具体行为差异,并通过多个实例展示如何精确控制用户登录 Shell、群组归属及目录结构。

2025.06.14 991
Linux umask命令详解:原理、计算与配置

在Linux系统中,新建文件和目录的初始权限由umask值决定。root用户默认umask为0022,普通用户为0002。文件最大权限666,目录777,通过遮盖运算得出最终权限。可通过命令行临时修改或编辑/etc/profile永久生效。

2026.11.17 990

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。