How to install and use PhotoRec to recover deleted files in Ubuntu 20.04

PhotoRec is an open-source software utility to recover lost or deleted media files like photos, videos, documents, etc from CD-ROMs, Hard disks, and digital camera memory. PhotoRec is associated with TestDisk. The TestDisk is used to recover deleted partitions and make non-bootable disks bootable again and photoRec recovers deleted media files or document files. It supports and can recover more than 480 file extensions.

When you accidentally deleted the file you better not add more media or document files to that memory or hard drive as you might overwrite your lost data. In this article, we will install and use PhotoRec to recover deleted files in ubuntu 20.04 LTS.

Installing PhotoRec

PhotoRec doesn't have it’s own package but it will come with the package while installing the TestDisk package. So, to install TestDisk execute the following command.

$ sudo apt update
$ sudo apt install testdisk -y

Once installation completes you can now perform the recovery task. As you can see in the following example I have deleted some of the images and we will be recovering these files.

Install TestDisk

Recovering Files Using PhotoRec

PhotoRec can be launched using the following command. On command execution, you will see the following interface where you can select your disk.

Recover lost files

Now, once the disk is selected, select proceed using the left and right key then hit enter. Then, you will see the following interface where you are requested to select the partition. You can select File Opt and filter files according to the selected extension only.

Ubuntu File Recovery

You can select the partition using the up and down arrow key and hit enter to the search. Next, select your filesystem type where the file will be stored and hit enter.

Choose partition to recover files from

Now, select the portion of the space to be analyzed. If you select Free, only the chosen partition disk’s unallocated space will be scanned and if you choose Whole all allocated partitions will be scanned.

Analyze harddisk

Now, select the directory where the recovered file will be saved then hit c to proceed with the recovery.

Choose recovered files destination directory

Once recovery is completed you will see the following output.

Recovery completed

All the recovered files will be saved inside the directory called recup_dir under the directory you set up before beginning the recovery. You may notice some other files also being recovered and file names also being changed as the PhotoRec the name according to its algorithm.

Conclusion

In this article, we learn to recover deleted files or lost files using PhotoRec in Ubuntu. You may find many other software like PhotoRec but it is way easier to use to recover the media files and documents.