Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

The 5 Best Linux Data Recovery Tools

Five free Linux tools that recover deleted files, lost partitions and failing disks, which one fits which accident, and the two rules to follow before you start.

3 min readBy Daniel

Reviewed by the AmazingRDP technical team

Linux data recovery tools

The best recovery is a backup on a second machine. See our dedicated servers for off-site backups. See Cheap Dedicated Servers from $38.99

A deleted file is not gone at once. The system only marks its space as free; the data stays until something new is written over it. Recovery tools look for that data. How much comes back depends on what happens between the accident and the attempt, so two rules come before any tool.

Two rules before you start

  1. Stop writing to the disk. Every new file may land on the data you want back. Do not install the recovery tool on that disk. If it is the system disk, shut the machine down and start from a live USB stick.
  2. Work on a copy when the disk is failing. A disk that clicks or reports errors gets worse with every read. Copy it once (tool 3), then recover from the copy.

On SSDs there is an extra catch: the TRIM function erases freed space within minutes or hours, and what TRIM has erased no tool can bring back.

Which tool for which accident

What happenedUse
A partition vanished, or the disk shows as emptyTestDisk
Files deleted or a card formatted; any file systemPhotoRec
The disk has read errors or is dyingddrescue first, then one of the others on the copy
Files deleted on ext3 or ext4, names wanted backextundelete or ext4magic
Recovering known file types from a disk imageForemost or Scalpel

1. TestDisk: lost partitions

sudo apt install testdisk
sudo testdisk

TestDisk searches a disk for partitions that are no longer in the partition table and writes the table again. When a whole disk suddenly appears "unallocated", this is the tool. It works through menus, and it writes nothing until you confirm.

2. PhotoRec: deleted files of any kind

sudo photorec

PhotoRec comes in the same package. It ignores the file system and searches the raw disk for the patterns of several hundred file types: photos, documents, videos, archives. It works even after a format. The price: file names and folders are lost, and you get numbered files to sort through. Save the results to a different disk.

3. ddrescue: copy a failing disk

sudo apt install gddrescue
sudo ddrescue -d -r3 /dev/sdb /mnt/backup/disk.img /mnt/backup/disk.map

ddrescue copies everything it can read, skips bad areas, then returns to them. The map file records progress, so the copy can be stopped and continued. The image must go to another, healthy disk with enough room. Afterwards, point TestDisk or PhotoRec at disk.img.

4. extundelete and ext4magic: ext3 and ext4

sudo apt install extundelete
sudo extundelete /dev/sdb1 --restore-all

These read the journal of ext3 and ext4, the usual Linux file systems, and can restore deleted files with their names and folders. The partition must be unmounted. Their success on ext4 is limited, because ext4 clears part of the information on deletion, and extundelete is no longer developed. Try it, and fall back to PhotoRec for what it misses.

5. Foremost and Scalpel: carving by file type

sudo apt install foremost
sudo foremost -t jpg,pdf,docx -i disk.img -o recovered/

Both do what PhotoRec does, with more control from the command line: you name the file types and they cut matching files out of a disk or an image. They are favourites in forensics, where the same search must be repeatable.

When to stop and call a specialist

  • The disk makes clicking or scraping noises, or is not detected at all.
  • The data is worth more than a recovery service costs.
  • The disk is encrypted and the key or header is damaged.

Each attempt on a physically damaged disk can destroy more. A laboratory can read it in ways software cannot.

The tool that always works: a backup

Recovery is luck; a backup is certainty. Keep copies on a second disk and on a machine somewhere else, and test a restore now and then. For a second location, see our dedicated servers. Related guides: uses for old hard drives (with the health check), clone Ubuntu Server with Clonezilla and why Ubuntu freezes.

Questions

Can deleted files be recovered in Linux?

Often, if nothing has been written over them. Stop using the disk at once and recover to a different disk.

What is the difference between TestDisk and PhotoRec?

TestDisk repairs partition tables and brings back lost partitions. PhotoRec recovers individual files by their content.

Can I recover files from an SSD?

Sometimes. TRIM erases freed space quickly, and data erased by TRIM cannot be recovered.

Are these tools free?

Yes. All five are free, open-source software.