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: