How to Recover Accidentally Deleted Linux Files with extundelete
This guide walks you through preparing a Linux disk, installing extundelete, protecting the affected partition, and using extundelete commands to locate and restore both files and directories that were mistakenly removed, ensuring safe data recovery for system administrators.
Linux File Deletion Recovery Using extundelete
Accidental deletion of files on a Linux system can be risky because there is no recycle bin; recovery requires careful steps. This article demonstrates a reliable method using the extundelete tool.
Preparation
Add a new disk to the virtual host (e.g., /dev/sdb)
Format and mount the disk
# mkfs.ext4 /dev/sdb
# mkdir /usr/local/dbdata/
# mount /dev/sdb /usr/local/dbdata/Delete test files
/usr/local/dbdata/gperftools-2.4.tar.gz # file
/usr/local/dbdata/pcre-8.32 # directoryExecute the accidental removal:
# rm -rf /usr/local/dbdata/gperftools-2.4.tar.gz /usr/local/dbdata/pcre-8.32Remount the partition as read‑only If the files are confirmed deleted and no backup exists, immediately protect the partition to prevent overwriting:
# mount -o remount,ro /dev/sdb
# mount -o remount,ro /usr/local/dbdata/Install extundelete Download and extract the tool:
# wget https://nchc.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2Install dependencies and compile:
# yum -y install gcc-c++ e2fsprogs.x86_64 e2fsprogs-devel.x86_64
# tar -jxvf extundelete-0.2.4.tar.bz2
# cd extundelete-0.2.4
# ./configure
# make && make installVerify installation: # extundelete -v Recover deleted files First, list deleted inodes (starting from the root inode 2):
# extundelete /dev/sdb --inode 2Note: Perform recovery on a different partition to avoid inode/block overlap.
Restore the specific file:
# extundelete /dev/sdb --restore-file gperftools-2.4.tar.gzRestore the deleted directory:
# extundelete /dev/sdb --restore-directory pcre-8.32Recovered items appear in a RECOVERED_FILES directory within the current working directory.
Summary
Use rm with caution.
Partition disks according to their function.
Know at least one method for data recovery.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
