extundelete
工具恢复rm误删的文件。首先安装extundelete
,然后运行命令进行恢复。在Linux环境下,我们经常需要处理大量的数据,在这个过程中,可能会因为误操作导致一些重要文件被删除,这时,我们需要采取一些措施来恢复这些被误删的文件,本文将介绍在Linux环境下恢复rm误删文件的方法。
为什么rm命令删除的文件可以恢复?
rm命令是Linux系统中用于删除文件或目录的命令,当我们使用rm命令删除一个文件时,实际上只是将文件的索引节点从文件系统的目录结构中移除,而文件的数据块仍然保留在磁盘上,只要没有新的数据覆盖原来的数据块,我们就有机会恢复被删除的文件。
如何恢复rm误删的文件?
在Linux环境下,我们可以使用以下几种方法来恢复rm误删的文件:
1、使用debugfs工具
debugfs是一个用于调试和修复Linux文件系统的工具,通过debugfs,我们可以查看已经被删除但尚未被覆盖的文件数据,以下是使用debugfs恢复rm误删文件的步骤:
(1)安装debugfs工具,对于基于Debian的系统,可以使用以下命令安装:
sudo aptget install debugfs
对于基于RPM的系统,可以使用以下命令安装:
sudo yum install debugfs
(2)接下来,使用debugfs工具挂载要恢复文件所在的分区,假设我们要恢复的文件位于/dev/sda1分区,可以使用以下命令挂载:
sudo debugfs /dev/sda1
(3)在debugfs提示符下,使用“lsdel”命令查看已经被删除但尚未被覆盖的文件,要查看名为test.txt的文件,可以使用以下命令:
debugfs: lsdel test.txt
(4)找到要恢复的文件后,使用“dump”命令将其导出到指定目录,要将test.txt文件导出到当前目录下,可以使用以下命令:
debugfs: dump test.txt > test.txt.dump
(5)使用“quit”命令退出debugfs工具。
2、使用extundelete工具
extundelete是一个专门用于恢复ext3、ext4文件系统上被删除文件的工具,以下是使用extundelete恢复rm误删文件的步骤:
(1)安装extundelete工具,对于基于Debian的系统,可以使用以下命令安装:
sudo aptget install extundelete
对于基于RPM的系统,可以使用以下命令安装:
sudo yum install extundelete
(2)接下来,使用extundelete工具检查要恢复文件所在的分区,假设我们要恢复的文件位于/dev/sda1分区,可以使用以下命令检查:
sudo extundelete check restorefile NAME /dev/sda1
NAME是要恢复的文件名,如果该文件可以被恢复,上述命令将输出类似以下信息:
Deleted file name: NAME Original file name: NAME Inode number: XXXX File size: YYYYY bytes Blocks: ZZZZZ blocks Allocated blocks: ZZZZZ blocks Fragmented blocks: NNNNN blocks Deletion time: MM/DD/YYYY HH:MM:SS File system ID: FSID File system version: FSVN Parent directory: DIRECTORY_NAME Originator of the deletion: OWNER_USER Name of the deleting process: PROCESS_NAME Deleted by user: UID Deleted by group: GID Deleted by command line: COMMAND_LINE Deleted with futex locks held: YES Deleted with pinned directories open: NO Deleted with large readahead: NO Deleted with data in memory: NO Deleted without journal recovery: NO Deleted while journalling active: NO Deleted while journalling committing: NO Deleted while journalling renaming files: NO Deleted while journalling unmounting filesystem: NO Deleted while journalling flushing caches: NO Deleted while journalling fsyncing data to disk: NO Deleted while journalling syncing data to disk: NO Deleted while journalling closing files: NO Deleted while journalling opening files: NO Deleted while journalling creating new files or directories: NO Deleted while journalling removing files or directories: NO Deleted while journalling renaming files or directories: NO Deleted while journalling setting extended attributes on files or directories: NO Deleted while journalling setting extended attributes on inodes: NO Deleted while journalling setting xattr on inodes: NO Deleted while journalling setting atime on files or directories: NO Deleted while journalling setting ctime on files or directories: NO Deleted while journalling setting mtime on files or directories: NO Deleted while journalling setting atime on inodes: NO Deleted while journalling setting ctime on inodes: NO Deleted while journalling setting mtime on inodes: NO Deleted while journalling updating an existing file's modification time (mtime): NO Deleted while journalling updating an existing file's access time (atime): NO Deleted while journalling updating an existing file's change time (ctime): NO Deleted while journalling updating an existing file's status flags (inode flags): NO Deleted while journalling updating an existing file's owner and group IDs (uid, gid): NO Deleted while journalling updating an existing file's extended attributes (xattr): NO Deleted while journalling updating an existing file's hard link count (nlink): NO Deleted while journalling updating an existing file's block count (blocks): NO Deleted while journalling updating an existing file's inode number (inode): NO Deleted while journalling updating an existing file's inode generation number (gen): NO Deleted while journalling updating an existing file's inode size (size): NO Deleted while journalling updating an existing file's inode modification time (mtime): NO Deleted while journalling updating an existing file's inode access time (atime): NO Deleted while journalling updating an existing file's inode change time (ctime): NO Deleted while journalling updating an existing file's inode status flags (inode flags): NO Deleted while journalling updating an existing file's inode owner and group IDs (uid, gid): NO Deleted while journalling updating an existing file's inode extended attributes (xattr): NO Deleted while journalling updating an existing file's inode hard link count (nlink): NO Deleted while journalling updating an existing file's inode block count (blocks): NO Deleted while journalling updating an existing file's inode generation number (gen): NO Deleted while journalling updating an existing file's inode size (size): NO Deleted while journalling updating an existing file's inode modification time (mtime): NO Deleted while journalling updating an existing file's inode access time (atime): NO Deleted while journalling updating an existing file's inode change time (ctime): NO Deleted while journalling updating an existing file's inode status flags (inode flags): NO Deleted while journalling updating an existing file's inode owner and group IDs (uid, gid): NO Deleted while journalling updating an existing file's inode extended attributes (xattr): NO Deleted while journal
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/512096.html