Accidentally deleting important files is a common problem many users face, whether by mistakenly hitting the wrong key, formatting a drive, or even system errors. Unlike some operating systems that move deleted files to a recycle bin or trash, files deleted on Linux systems like Ubuntu can sometimes be tricky to recover, especially if the deletion bypassed the Trash or happened via terminal commands.
Deletion Does Not Immediately Erase Data:
When a file is deleted, Linux doesn’t instantly erase the actual data on the disk. Instead, it removes references (pointers) to the file in the filesystem’s metadata, marking the sectors on the disk as available for new data.

Filesystem Matters:
Ubuntu commonly uses ext4. but other filesystems like ext3. xfs, btrfs, or NTFS (on external drives) are possible. Each filesystem handles deletion differently, affecting recoverability.
Data Overwriting Risk:
Once a file is deleted, new data written to the disk may overwrite the sectors holding the deleted file, making recovery impossible. Therefore, minimize disk usage immediately after deletion to maximize recovery chances.
Trash vs. Permanent Deletion:
Files deleted via the Ubuntu desktop file manager usually move to the Trash folder (~/.local/share/Trash). Files deleted using rm or by emptying Trash bypass this, becoming harder to recover.
Preparing for Recovery
Important Preliminary Steps
Stop Using the Affected Drive:
Continuing to use the disk risks overwriting deleted data.
Use a Live USB:
Boot Ubuntu from a live USB to avoid writing to the affected drive during recovery.
Mount Drives as Read-Only:
If possible, mount the partition containing deleted files in read-only mode.
Recovery Destination:
Always recover files to a separate drive or partition to prevent overwriting data.
Tools for Deleted File Recovery on Ubuntu
Several powerful tools are available for recovering deleted files on Ubuntu. Some have graphical interfaces, others are command-line based. Here’s a rundown:
1. Panda Assistant
Losing important files can be stressful, whether due to accidental deletion, system crashes, or other unexpected errors. Panda Assistant offers a reliable and user-friendly solution for deleted file recovery, helping users restore lost data quickly and safely on their devices.
Panda Assistant is designed to recover deleted files from a variety of storage media, including hard drives, SSDs, USB flash drives, memory cards, and more. It supports recovery of many common file types such as documents, photos, videos, audio files, emails, and archives, making it a versatile tool for personal and professional use.
One of the key advantages of Panda Assistant is its straightforward interface, which allows users—regardless of technical expertise—to navigate the recovery process with ease. By scanning the storage device deeply, Panda Assistant can identify recoverable files even after they’ve been permanently deleted or removed from the recycle bin.
2. PhotoRec
Purpose: File recovery tool bundled with TestDisk.
Features: Recovers files by scanning for known file headers, supports many file types.
Use Case: Great for recovering photos, documents, videos from formatted drives or partitions.
Installation: Installed with TestDisk.
Usage:
nginx
CopyEdit
sudo photorec
Follow prompts to select disk and file types.
3. extundelete
Purpose: Undelete files from ext3 and ext4 partitions.
Installation:
nginx
CopyEdit
sudo apt install extundelete
Usage:
Must be run on an unmounted partition or mounted read-only.
Example:
bash
CopyEdit
sudo extundelete /dev/sdX –restore-file path/to/file
or
bash
CopyEdit
sudo extundelete /dev/sdX –restore-directory path/to/directory
4. Scalpel
Purpose: File carving tool that recovers files based on headers and footers.
Installation:
nginx
CopyEdit
sudo apt install scalpel
Usage:
Configure /etc/scalpel/scalpel.conf for the types of files to recover, then run:
bash
CopyEdit
sudo scalpel /dev/sdX -o output_directory
5. R-Linux
Purpose: GUI tool for recovering files from ext2/ext3/ext4.
Availability: Available as a free download from its website.
6. Foremost
Purpose: File carving tool similar to Scalpel.
Installation:
nginx
CopyEdit
sudo apt install foremost
Usage:
bash
CopyEdit
sudo foremost -i /dev/sdX -o output_directory
Step-by-Step Deleted File Recovery Guide on Ubuntu
Scenario 1: Recover Files Deleted from Trash
If files are deleted but still in Trash:
Open Trash from your Ubuntu desktop.
Right-click files and select “Restore.”
Alternatively, move files from Trash folder in terminal:
bash
CopyEdit
mv ~/.local/share/Trash/files/filename ~/Recovered/
Scenario 2: Recover Files Deleted Using rm
Files deleted with rm bypass Trash and need recovery tools.
Using TestDisk to Recover Deleted Files:
Install TestDisk:
nginx
CopyEdit
sudo apt install testdisk
Run TestDisk:
nginx
CopyEdit
sudo testdisk
Select “Create” to start a new log file.
Select the disk containing the deleted file.
Choose the partition table type (usually Intel/PC for standard drives).
Select “Advanced” for file system utilities.
Choose the partition, then “Undelete.”
Browse the list of deleted files and select those to recover by pressing c (copy).
Select a recovery destination on a separate drive or partition.
Exit TestDisk after recovery completes.
Using extundelete to Recover Deleted Files from ext4 Partition:
Unmount the partition:
bash
CopyEdit
sudo umount /dev/sdXN
Run extundelete:
bash
CopyEdit
sudo extundelete /dev/sdXN –restore-all
This recovers all deleted files to a folder named RECOVERED_FILES in the current directory.
Check the recovered files and move them safely.
Recovering Files from Formatted Drives or Deleted Partitions
If a drive or partition has been formatted or deleted, recovery gets harder but is often still possible.
Using PhotoRec:
Run PhotoRec:
nginx
CopyEdit
sudo photorec
Select the disk.
Choose the partition (or whole disk if unsure).
Choose the file system type (usually ext2/ext3/ext4 or FAT/NTFS).
Select “Whole” or “Free” space to scan.
Choose file types to recover or select all.
Set the recovery destination folder on a different disk or partition.
Start the recovery process and wait.
PhotoRec scans the disk sector by sector, looking for file signatures and recovers any found data regardless of filesystem metadata.
Tips for Improving Recovery Success
Stop using the affected disk immediately.
Writing new data can overwrite deleted files.
Use live boot media to avoid writing to the disk.
Recover files to a different disk or USB drive.
Prioritize recovery of critical files first.
Keep backups to prevent future data loss.
Understanding Limitations and Risks
Overwritten files cannot be recovered.
File recovery tools may restore files without original filenames or folder structure.
Partial or corrupt recovery is possible depending on file system state.
Data recovery is not guaranteed; professional help may be necessary for severe cases.
Advanced Recovery Techniques
Mounting Drives Read-Only
To avoid any writes, mount the drive read-only:
bash
CopyEdit
sudo mount -o ro /dev/sdXN /mnt/recovery
Using dd to Create a Disk Image
Create a raw image backup before recovery attempts:
bash
CopyEdit
sudo dd if=/dev/sdX of=/path/to/backup.img bs=4M status=progress
Then perform recovery operations on the image to protect the original disk.
Using Sleuth Kit for Forensic Analysis
The Sleuth Kit provides powerful forensic analysis tools that can help recover deleted files:
Install:
nginx
CopyEdit
sudo apt install sleuthkit
Use tools like fls to list deleted files, and icat to extract them.
Preventing Future Data Loss
Regularly back up important data using tools like rsync, Ubuntu’s Backup utility, or cloud services.
Use version control for important documents and code.
Use Trash instead of terminal delete commands when possible.
Consider enabling filesystem snapshots with tools like btrfs or LVM for easy rollback.
Recovering deleted files on Ubuntu requires understanding how Linux handles file deletion, acting quickly, and using the right tools. While success cannot be guaranteed, powerful utilities like TestDisk, PhotoRec, extundelete, and others offer strong chances to restore lost data if used correctly.
About us and this blog
Panda Assistant is built on the latest data recovery algorithms, ensuring that no file is too damaged, too lost, or too corrupted to be recovered.
Request a free quote
We believe that data recovery shouldn’t be a daunting task. That’s why we’ve designed Panda Assistant to be as easy to use as it is powerful. With a few clicks, you can initiate a scan, preview recoverable files, and restore your data all within a matter of minutes.
Subscribe to our newsletter!
More from our blog
See all postsRecent Posts
- Recover data from damaged hard drive 2025-06-13
- How to recover data off a hard drive 2025-06-13
- Hard drive is damaged how to recover 2025-06-13