Deleted files are easiest to recover before the source filesystem receives more writes. PhotoRec can carve documents, archives, photos, and videos from raw disk data, but every package install, browser cache, log entry, or copy operation on the affected filesystem can overwrite blocks that still contain the missing content.
PhotoRec is part of the testdisk suite and searches for file signatures instead of relying on directory entries. That makes it useful when a partition has been reformatted, metadata is missing, or a normal undelete tool cannot list the deleted path. The tradeoff is that recovered files usually lose their original filenames and folder hierarchy.
Run the scan from a live Linux session or another machine when the lost data lived on the system disk, and write the recovered output to a different mounted filesystem. Choose the ext2/ext3/ext4 filesystem mode only for those source filesystems; choose Other for FAT, NTFS, exFAT, XFS, Btrfs, and other non-ext sources.
Do not install packages, download files, copy data, or keep normal services writing to the source filesystem after deletion. New writes can overwrite blocks that PhotoRec would otherwise recover.
The destination must not be the filesystem being recovered. Avoid a FAT32 destination when recovered files may exceed 4 GB.
For Ubuntu live media, choose Try Ubuntu so logs, swap, package operations, and desktop caches stay off the affected disk.
$ sudo apt install testdisk
Most distributions package photorec with testdisk. Use sudo dnf install testdisk on Fedora-family systems or sudo pacman -S testdisk on Arch-family systems.
$ photorec /version PhotoRec 7.2, Data Recovery Utility, February 2024 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Version: 7.2
$ lsblk --fs NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS sdb `-sdb1 ext4 1.0 photos 064e84d3-b7e4-45d0-89ba-6b28df345687 72G 41% /media/live/photos sdc `-sdc1 ext4 1.0 recover 88b2857a-64f5-4c0f-829d-470f4e8d93fd 430G 12% /mnt/recovery
Use the whole disk such as /dev/sdb when the partition table is damaged or the deleted files may span partitions. Use the partition device such as /dev/sdb1 when the lost files came from one known filesystem.
$ findmnt /mnt/recovery TARGET SOURCE FSTYPE OPTIONS /mnt/recovery /dev/sdc1 ext4 rw,relatime
$ sudo photorec /d /mnt/recovery/photorec /dev/sdb
Replace /dev/sdb and /mnt/recovery/photorec with your source device and destination prefix. With /d, PhotoRec writes output to numbered paths such as /mnt/recovery/photorec.1 and increments the suffix if that path already exists.
Open [ File Opt ] only when you need to recover a narrow set of file families such as jpg, zip, or pdf. Leaving the defaults enabled avoids missing formats that were not obvious before the scan.
Choose [ ext2/ext3/ext4 ] only for ext2, ext3, or ext4 source filesystems. Choose [ Other ] for FAT, NTFS, exFAT, XFS, Btrfs, and other filesystem types.
Use [ Free ] when the filesystem metadata is readable and the goal is deleted files from unallocated space. Use [ Whole ] when the source was reformatted, the filesystem is damaged, or the free-space-only choice is unavailable.
PhotoRec writes recovered files and report.xml into paths such as /mnt/recovery/photorec.1. It creates another numbered path when the destination prefix already exists.
$ ls /mnt/recovery/photorec.1 f0000128_notes.zip report.xml
$ file /mnt/recovery/photorec.1/f0000128_notes.zip /mnt/recovery/photorec.1/f0000128_notes.zip: Zip archive data, at least v1.0 to extract, compression method=store
Recovered filenames usually begin with f, b, or t instead of the original name. Use extensions, file output, embedded timestamps, and application previews to sort the results.
$ unzip -l /mnt/recovery/photorec.1/f0000128_notes.zip
Archive: /mnt/recovery/photorec.1/f0000128_notes.zip
Length Date Time Name
--------- ---------- ----- ----
38 2026-06-13 11:19 notes.txt
--------- -------
38 1 file
Do not resume writes to the original source disk until the recovered files have been reviewed. If the first pass misses important data, run a second pass with different [ File Opt ] settings or a [ Whole ] scan before returning the source filesystem to normal use.