Get Updates by Email

Friday, 21 September 2012

Photorec's Miraculous File Recovery System

Recently I formatted a USB drive by mistake. In it were precious photos and other documents. I thought back to the time when I had done so before, and promptly thought of Photorec, which is a miraculous program that helps recover deleted data from all kinds of storage, even formatted storage.

As of a few months back, I've started using the Ubuntu-based Mint Linux for my personal laptop. It beats Mageia in stability, at least for me, and everything just "works out of the box". Naturally, there are some hardware device driver issues with Linux, so I've made it a point to buy only Brother printers / all-in-one's because of their excellent support for Linux.

You can download PhotoRec from its webpage here. Here is a sample text from the website:
PhotoRec is file data recovery software designed to recover lost files including video, documents and archives from hard disks, CD-ROMs, and lost pictures (thus the Photo Recovery name) from digital camera memory. PhotoRec ignores the file system and goes after the underlying data, so it will still work even if your media's file system has been severely damaged or reformatted.

The program is run as shown on this page. I used the command:
./photorec_static /d Recover /dev/hdb 

Explanation: I was using the command line, and there was a sub-directory called "Recover". I told PhotoRec to put all the files that it "recups" into "Recover". And finally PhotoRec would need to examine device "/dev/hdb", which is a plug-in USB drive.

After much hours, finally the process stopped. PhotoRec will report to you how many files have been recovered, and try to classify them. Better yet, in the "recup directory", there will be many sub-directories, where files are recovered and saved in sequential naming.

Unfortunately, this causes the problem that there may be too many files. I did some Google searching and found this Ubuntu page on recursive copying of files. Since Mint Linux is based on Ubuntu, I figured out that the commands are usable.

I decided to find all the image files with extensions "JPEG" and "JPG" under "Recover", and transfer all of them to a new sub-directory called "jpg-Recover". The end result was that all the JPG files under "Recover" (and its sub-directories) got copied to "jpg-Recover" (which is the same level as "Recover".

Here is the command I used:
find Recover -name *.jpg -type f -exec cp '{}' jpg-Recover \;

I am grateful for the guys at Ubuntu Forum for their nifty Q&A's.

Update: Having put all the JPG's and JPEG's into one directory, I decided to sort the image files. I found a solution in the website, in a Q&A "How to sort images into folders based on resolution". The solution is based on a script by user "Zatatlan".

for image in *.jpg;
    do res=$(identify -format %wx%h\\n $image);
    mkdir -p $res;
    mv $image $res;

Here is what I did.

First, I saved the script into my /home folder under its own sub-directory: /jpg_sort. The script was saved as

Second I launched Nautilus and made the file executable.

Third I went to "jpg-Recover" and ran the bash script as superuser.

I haven't seen the results yet, but here's keeping my fingers crossed.