Recovering Deleted Data on Linux…

Imagine this situation -  “you are browsing through your photos on your camera or on your your thumb drive.  You decide to clean up the unwanted photos/data and start deleting files.  All of a sudden you realize you deleted your best photo or that important file. How do you get the data back?”

Firstly dont create any new files or copy any new data on the disk.  This will make sure that the data is recoverable (once the sectors where your file used to reside get overwritten its impossible to recover).

Now there are two simple solutions I found for recovery problems.  Both work best in different situations:

GDDRescue

ddrescue is a simple program that copy bit by bit information form one area of the hard disk to another.  It has loads of amazing features but the one that I like the most is that it ignores unreadable sectors and moves on.  This feature is very useful when recovering movies.  It also makes it easy to recover media files if you have the torrent from which you originally downloaded the file.

sudo apt-get install gddrescue

ddrescue -r 3 /media/cdrom/movie.avi /home/user/movie.avi

In the above command
-r 3 :- makes the program to retry to recover data from a bad sector 3 times and then move on.
/media/cdrom/movie.avi :- The input file
/home/user/movie.avi :- The recovered file

Foremost:

Foremost is a simple application that recovers data from a damaged disk. It goes one step better by sorting out the information for the common file types. The output of Foremost is a directory which has a series of subdirectories where files like jpg, avi, mpg, bmp ect are recovered and stored. This is a perfect application to recover specific data from a disk

To install Foremost use the following command:

sudo apt-get install foremost

To run foremost use the following command:

sudo foremost -i /dev/sdb1 -o /recovery/disk

In the above command
-i indicates the partition/file to be recovered from.
-o indicates the output directory where the recovered files will be stored.

Once the recovery is done you will need to change the ownership of the output directory so that you can read the files. Use the following command to do that:

sudo chown -R username /recovery/disk

Ps: There are more complex methods and applications to do data recovery on Linux. These two are the simplest I have used. Feel free to share your suggestions in the comments.