Recover Deleted Files Kali Linux: Full Guide
In this article
- Why Deleted Files Aren't Immediately Gone
- Preparing to Recover: Stop Using the Drive
- Tool 1: TestDisk (For Recovering Deleted Partitions and Files)
- Tool 2: PhotoRec (For Carving Files by Content)
- Tool 3: extundelete (For ext3/ext4 Filesystems)
- Choosing the Right Tool
- Common Problems and Misconceptions
- Safety and Legal Considerations
- Frequently Asked Questions
Yes, you can recover deleted files on Kali Linux using built-in tools like testdisk and photorec, or command-line utilities such as extundelete and foremost. The success of recovery depends on how quickly you stop writing new data to the drive and which filesystem you are using.
Why Deleted Files Aren't Immediately Gone
When you delete a file in Linux, the operating system doesn't erase the actual data. It simply removes the file's entry from the filesystem index (like the inode table on ext4). The space is marked as available, but the underlying bits remain on the disk until overwritten by new data. This is why recovery is possible — but it's a race against time.
Kali Linux is a Debian-based distribution focused on security testing, so it includes a set of tools that are also excellent for file recovery. Unlike Windows or macOS, Kali gives you direct access to raw disk devices, which is essential for deep recovery.
Preparing to Recover: Stop Using the Drive
The single most important step is to stop writing anything to the affected drive. Even a simple boot process can write logs, temporary files, or update access times, overwriting the very data you want to restore.
- If the deleted file was on your system drive, boot Kali from a live USB instead of the installed system.
- If it's an external drive or a separate partition, unmount it immediately:
sudo umount /dev/sdX. - Work on a copy of the drive if possible. Use
ddto create an image:sudo dd if=/dev/sdX of=/path/to/image.img bs=4M.
Working on a copy is safer because you can experiment without risking further damage to the original.
Tool 1: TestDisk (For Recovering Deleted Partitions and Files)
TestDisk is a powerful utility that can recover lost partitions and repair boot sectors. It also has a file recovery mode for common filesystems like ext4, NTFS, and FAT.
- Open a terminal and run
sudo testdisk. - Select the disk containing the deleted file and choose Proceed.
- Choose the partition table type (usually Intel for MBR or EFI GPT).
- Select Advanced, then choose the partition where the file was.
- Select Undelete and browse the directory tree. Deleted files are shown in red.
- Copy the file to a different drive.
TestDisk works best when the filesystem structure is intact. If the partition itself was deleted, TestDisk can often rebuild it.
Tool 2: PhotoRec (For Carving Files by Content)
PhotoRec is a companion tool to TestDisk. It ignores the filesystem and scans raw data blocks for file signatures (like JPEG headers, ZIP magic numbers, or PDF markers). This makes it effective even if the filesystem is damaged or formatted.
- Run
sudo photorec. - Select the disk and partition.
- Choose the filesystem type (or leave as Other for raw carving).
- Select a destination directory on a different drive.
- Start the scan. It will take a long time on large disks.
PhotoRec doesn't preserve original filenames — it saves files as f123456.jpg etc. But it's your best bet when the filesystem is severely damaged.
Tool 3: extundelete (For ext3/ext4 Filesystems)
If your partition uses ext3 or ext4 (common in Linux), extundelete can recover files using the journal. It's fast and can restore the original filename and directory structure.
sudo extundelete /dev/sdX --restore-file /path/to/file
sudo extundelete /dev/sdX --restore-directory /home/user/Documents
Extundelete works best when the file was recently deleted and the journal still has the metadata. If the journal has been overwritten, it may only recover fragments.
Choosing the Right Tool
There's no one-size-fits-all answer. Here's a quick guide based on your situation:
- File deleted, filesystem intact: Use TestDisk's Undelete or extundelete.
- Partition deleted or formatted: Use TestDisk to rebuild the partition, then recover files.
- Filesystem corrupted or unknown: Use PhotoRec for content-based carving.
- Multiple files or entire directories: PhotoRec or extundelete with the
--restore-directoryoption.
For NTFS drives (from Windows), you can also use ntfsundelete or the ntfs-3g package's tools. For FAT32, fatcat or testdisk work well.
Common Problems and Misconceptions
Problem: I deleted the file and then ran a disk check (fsck). That's one of the worst things you can do. fsck writes to the filesystem and can overwrite the very inodes you need. Always run recovery tools before any filesystem repair.
Misconception: Recovering from an SSD is the same as from an HDD. SSDs use TRIM, which permanently erases deleted blocks almost immediately. If TRIM is enabled, recovery is usually impossible. For SSDs, you need to act before the drive performs a garbage collection cycle.
Problem: The file is recovered but is corrupted. This happens when part of the file was overwritten. PhotoRec may give you a file that opens but has missing sections. The only solution is to recover from a backup or accept partial recovery.
Safety and Legal Considerations
File recovery tools are powerful, but they can also be used for malicious purposes. In many jurisdictions, recovering someone else's files without permission is illegal. Always ensure you have the right to access the data you're trying to recover.
Also, be aware that recovery tools can damage the filesystem further if used incorrectly. Always read the documentation and start with a copy of the drive.
Frequently Asked Questions
Can I recover files from a formatted partition?
Yes, if the partition was formatted but not overwritten. PhotoRec can scan the raw disk and find files by their signatures. The chances decrease if you've written a lot of new data after formatting.
Is there a GUI tool for recovery in Kali?
Yes, you can install forensics-all which includes several GUI tools, or use gparted for partition recovery. However, most recovery tools are command-line based, and that's often more reliable.
How long does recovery take?
It depends on the disk size and the method. A quick extundelete on a recent deletion might take seconds. A full PhotoRec scan of a 1TB drive can take hours or even a day. Be patient.
Will recovery work on a USB stick?
Yes, the same tools work on USB drives, SD cards, and other removable media. The same rules apply: stop using the device immediately and work on a copy if possible.
What if the file was deleted from the Trash?
In Kali's default file manager, moving a file to Trash doesn't actually delete it — it moves it to ~/.local/share/Trash/files. You can simply restore it from there. If you emptied the Trash, then the file is truly deleted and you need the tools above.