PhotoRec – Recover Deleted or Lost Files in Linux

When you delete a file accidentally or intentionally on your system using ‘shift + delete‘ or delete option or empty Trash, the file content is not destroyed from the hard disk (or any storage media).

It is simply removed from the the directory structure and you cannot see the file in the directory where you deleted it, but it still remains somewhere in your hard drive.

If you have the appropriate tools and knowledge, you can recover lost files from your computer. However, as you store more files on your hard disk, the deleted files are overwritten, you may only recover recently deleted files.

In this tutorial, we will explain how to recover lost or deleted files on a hard disk in Linux using Testdisk, is a remarkable recovery tool ships in with a free tool called PhotoRec.

PhotoRec is used to recover lost files from storage media such as hard drives, digital camera and cdrom.

Install Testdisk (PhotoRec) in Linux Systems

To install Testdisk by running the relevant command below for your distribution:

------- On Debian/Ubuntu/Linux Mint ------- 
$ sudo apt-get install testdisk

------- On CentOS/RHEL/Fedora ------- 
$ sudo yum install testdisk

------- On Fedora 22+ ------- 
$ sudo dnf install testdisk   

------- On Arch Linux ------- 
$ pacman -S testdisk             

------- On Gentoo ------- 
$ emerge testdisk  

In case it is not available on your Linux distribution’s repositories, download it from here and run it on a Live CD.

It can also be found in rescue CD such as Gparted LiveCD, Parted Magic, Ubuntu Boot CD, Ubuntu-Rescue-Remix and many more.

Once the installation is complete, start PhotoRec in a text window as follows with root privileges and specify the partition from which the files where deleted:

$ sudo photorec /dev/sda3

You’ll see the interface below:

PhotoRec Data Recovery Tool for Linux
PhotoRec Data Recovery Tool for Linux

Use the right and left arrow keys to select a menu item, and press Enter. To continue with the recovery operation, select [Proceed] and hit Enter.

You will be at the following interface:

Select Partition to Proceed File Recovery
Select Partition to Proceed File Recovery

Select [Options] to view available recovery operation options as in the interface below:

Linux File Recovery Options
Linux File Recovery Options

Press Q to move back, at the interface below, you can specify the file extensions you want to search and recover. Therefore, select [File Opt] and press Enter.

Press s to disable/enable all file extensions, and in case you have disabled all file extensions, only choose types of files you want to recover by selecting them using right arrow keys (or left arrow key to deselect).

For instance, I want to recover all .mov files that I lost on my system.

Specify Recovery File Type
Specify Recovery File Type

Then press b to save the setting, you should see the message below after pressing it. Move back by hitting Enter (or simply press Q button), then press Q again to go back to the main menu.

Save File Recovery Settings
Save File Recovery Settings

Now select [Search] to start the recovery process. In the interface below, choose the filesystem type where the file(s) were stored and hit Enter.

Select Filesystem to Recover Deleted Files
Select Filesystem to Recover Deleted Files

Next, choose if only free space or the whole partition needs to be analyzed as below. Note that choosing whole partition will make the operation slower and longer. Once you have selected the appropriate option, press Enter to proceed.

Choose Filesystem to Analyze
Choose Filesystem to Analyze

Closely select a directory where recovered files will be stored, if the destination is correct, press C button to continue. Choose a directory on a different partition to avoid deleted files being overwritten when more data is stored on the partition.

To move back until the root partition, use the left arrow key.

Select Directory to Save Recovered Files
Select Directory to Save Recovered Files

The screenshot below shows deleted files of the specified type being recovered. You can stop the operation by pressing Enter.

Note: Your system may become slow, and possibly freeze at certain moments, so you need to be patient until when the process is complete.

Recovering Deleted Files in Linux
Recovering Deleted Files in Linux

At the end of the operation, Photorec will show you the number and the location of files recovered.

Linux File Recovery Summary
Linux File Recovery Summary

The recovered files will be stored with root privileges by default, therefore open your file manager with elevated privileges to access the files.

Use the command below (specify your file manager):

$ gksudo nemo
$ gksudo nautilus 

For more information, visit PhotoRec homepage:

That’s all! In this tutorial, we explained the necessary steps to recover deleted or lost files from hard disk using PhotoRec. This is so far the most reliable and effective recovery tool I have ever used, if you know any other similar tool, do share with us in the comments.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

37 thoughts on “PhotoRec – Recover Deleted or Lost Files in Linux”

  1. I accidentally deleted 100 GB of folders and files. Recovering right now. Seems to work! Thank you. However, many new folders and randomly named files. Do you have a strategy for finding what among thousands of pointless files (e.g. cached web-content…)?

    • @Bo

      You will always see new folders and randomly named files, this is part of any data recovery process. You have to manually dig through to find all your important folders and files.

  2. I downloaded, followed the install instructions, it installed, tried:

    $ sudo photorec /dev/sda3

    and got this message:

    PhotoRec 7.0, Data Recovery Utility, April 2015
    Christophe GRENIER
    Unable to open file or device /dev/sda3: No such file or directory
  3. Wow, great writeup.
    I had to pull the chip out of my Canon to make it visible as a recoverable disk, but once I did, thes instructions recovered every photo!

  4. I tried to move photos from my camera to a new folder on my hard drive but the folder landed in the camera storage by mistake. So the photos were moved into the folder and I am unable to access the folder, which is also now no longer visible.

    I have tried to recover the photos by directing PhotoRec to the folder by “sudo photorec nikon dsc coolpix l19ptp dcim 104 nikon” and have tried various spacing and / combinations but am not sure if I am on the right track re specifying the locality of the folder.

    My operating system is Ubuntu 16.04 Unity.

    • @Jan

      Specify the partition from which the files where deleted, this is the camera storage represented by a file under /dev/ filesystem. You can find more information about the mount point and dev file for your camera in Linux, possibly by searching the web.

  5. Exactly – Do not panic! In bulk cases, deleted files can reanimate – even if you have cleared the trash or did not used the trash when deleting files.

    For effective resuscitation deleted data should execute some actions. Do not be discouraged – for this, it is not necessary to be an expert in the field of information technology, you also do not need to pay hundreds of dollars to a specialist professional for restoration of your remote information.

  6. Hi,

    It was really working superb. nice article i recovered my photos simply and very easily. thank you for sharing this post with us. keep moving

  7. Hi,

    I accidentally deleted the a picture folder that has many folders inside (like 001,002,003,004..etc), can it restore the whole folder structure? or just get the files back?


  8. not working only creating a lots of directory like recup_dir.(1..33) . inside that directory nothing found useful to recover the files or folder…

    • @niraj

      Did you specify the type of files you want to recover, i mean the extensions? It worked fine for me, however, if you have stored more files recently on the partition you are trying to recover from, your files deleted earlier on get overwritten.

      Try to use it on another partition and see if it works. Thanks for the feedback.


Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.