How To: Recover Deleted Files in Linux Using Photorec

Frequently I get messages like “I have accidentally deleted my project. Is there any way to recover it in Linux?” or “I worked really hard on that program and managed to deleted it right before submission 🙁 How do I recover?”. Well I didn’t really have any idea on “How to actually recover deleted files in Linux”.

A few days back I was designing the new logo for Videocache in Inkscape. After finishing the design, I saved the svg file carefully. And deleted other images which I embedded in the logo. A few moments later I realized that I just screwed up myself by deleting all those files as the svg file is now good for nothing.

I searched a lot on recovering files in Linux but in vain. Then a friend (bitgeek) told me about Photorec. I managed to recover all the files using photorec. I thought it would be a good idea to let others know and spread a good word about Photorec. Below is a step by step howto on using Photorec to recover your files.

What is Photorec?

From Photorec website,

PhotoRec is file data recovery software designed to recover lost files including video, documents and archives from Hard Disks and CDRom and lost pictures (thus, its ‘Photo Recovery’ name) from digital camera memory. PhotoRec ignores the filesystem and goes after the underlying data, so it will still work even if your media’s filesystem has been severely damaged or re-formatted.

For This HowTo

Lets say I had a file download_arrow.png in /home/saini/Desktop which I have removed accidentally. Login as root and create a directory recover which will be used to store all the recovered files.

Install testdisk/PhotoRec

Photorec comes as a part of testdisk package in Fedora (I hope its same for other distributions as well). Use yum to install testdisk.

[root@fedora-tips ~]$ yum install testdisk

Launch Photorec

Once you are done with installation. Open a terminal and launch photorec (as root).

[root@fedora-tips recover]$ photorec

Select Hard Disk

If you have more than one hard disk in your system, select the one from which you have deleted the file(s).

PhotoRec Hard Disk Selection

Select Partition Type

If your hard disk has Linux partitions, then select [Intel].

PhotoRec Partition Selection

Select Filetype Option

Move to [File Opt] and press enter. Here you can disable all file types by pressing ‘s’ . Use space to toggle the check button. Now since we removed a png file, we are going to check only png file type.

PhotoRec Filetype Selection

Select Options

Photorec also has a list of different options. Under normal circumstances you don’t need to modify them

PhotoRec Option Selection

Select Partition

Move the selector to the partition from which you have removed the file. Then press enter on search.

PhotoRec Partition Selection

Select Filesystem Type

If you are using Linux, its going to be ext2/ext3/ext4. So the default selection is file.

PhotoRec Partition Selection

Select Space for Analysis

Select free if you didn’t write to that partition after removing the particular file otherwise select whole.

PhotoRec Space Selection

Select a Directory to Recover Files

Now select the path where the recovered files will be stored. Then press ‘Y’.

PhotoRec Recovery Directory Selection

Recovery Progress

Photorec will show how many files it has recovered.

PhotoRec Recovery Progress

All recovered file will be stored in the directory selected above. Open them in a file browser and you’ll get the removed file there. I hope this howto will help you recovering files you accidentally delete 🙂

 

Bye Bye Windows

A ruff day again … but a day I think I’ll remember for long or may be forever … the day of change … the day you grow up and take decision not to mess up your life anymore …

well, ORB posted some pics of a game here (intranet link) and I just asked about the minimum hardware configuration for running the game. His reply was minimum requirements for u is first start using windows“. well, I use linux most of the times but I have windows xp as well, though sitting idle on my hdd. I didn’t a expect a comment like that.

As I am leaving for home on 10th of this month, I switched to windows. I started writing some data onto DVDs for taking them along with me. While writing the first DVD, it failed at 95%. Suddenly, I got an idea that I would take my hard disk instead of writing the DVDs this time. I’ll buy a SATA to USB converter and transfer the data through USB. So, started collecting the data. While downloading a movie from some ftp, a virus came over and attacked my pc. Strange virus!!! whenever I open any window with title having any of the words task manager, antivirus, virus, norton, symantec, mcaffee etc., it just minimize the window and kill the process immediately. ohh !!! I tried all the ways I know or I could have, but in vain.

So, thought of formatting my windows partition and reinstall the windows. Booted from the xp cd and …. and black screen …. ohh god … i have got this SATA-II hdd. shit!!! Technology is just to fool humans not to help in the real sense. The windows xp doesn’t install on sata hard disks.

To get through, I had two ways … either I go by the long, irritating way of patching the xp iso with sata drivers or format the entire hdd and create one single partition using Partition Magic and then install the xp. Tried patching first … long long process … gave up early … and there is not point in formatting the entire hdd for the crappy os. The best thing is that Fedora 7 is out with a great support for virtualization.

So, I have finally decided to kick windows out of my hdd forever or as long as possible and keep only Fedora. I will really miss AOE but I can’t live with the threats anymore.

I remember a line from one of our English books “Calamity will come and teach them by torture.”. I think this is going to happen to everyone sometime down the line.

So, from now on, I am totally free and secure.