/home/shakir

Recover deleted files with photorec

Posted on 31 Oct, 2007, categorized under Information Insemination



I was just watching a movie while suddenly all the files except the hidden ones in my home directory were gone, just as someone issued the command

sudo rm -rf /home/shakir/*

To avoid further data loss, I quickly power off and boot into my Ubuntu live CD to create an image of my /home partition. Here’s how to see in which partition is my /home directory:

shakir@herugrim ~ $ cat /proc/partitions
major minor  #blocks  name
8     0  156290904 sda
8     1   21494938 sda1
8     2    8795587 sda2
8     3    2939895 sda3
8     4          1 sda4
8     5    9775521 sda5
8     6  113282316 sda6

From the partition sizes I can tell my /home partition was in the /dev/sda6, and the next step is to really create an image of the partition to safely doing the recovery process without risking of losing more data. /media/usbdisk is where my external usb harddisk is mounted

sudo dd if=/dev/sda6 of=/media/usbdisk/herugrim-sda6-20071010.img

Photorec is part of testdisk package, and this is how to install it in ubuntu;

sudo apt-get update
sudo apt-get install testdisk

It’s time to actually do run the program

sudo photorec /home/shakir/temp/herugrim-sda6-20071010.img

After going through some options, photorec starts doing it’s job.

Photorec stores recovered files in recup_dir.<sequence>/<sequence>.<file extension> in the specified target directory, which is not very useful. Here’s a script I wrote to find all the recovered JPEG files and move/rename it accordingly. Almost the same technique can be used for other file formats.

#!/bin/bash
PHOTODIR=/home/shakir/temp/photorec
cd $PHOTODIR
mkdir JPEG
for i in `ls | grep recup`;do
	for j in `ls $i/*.jpg`; do
		if FILE=`exiv2 $j 2>/dev/null | grep timestamp | awk ‘{ print $4"-"$5 }’ | tr -d ‘:’ | grep 200`; then
			cp -v $j "JPEG/"$FILE".jpg"
		fi
	done
done
Tags: , ,




Looking for something else? Search Google.

4 Responses to "Recover deleted files with photorec"

1 | izlan

October 31st, 2007 at 2:22 pm

Avatar

sifu, kalo dah create image cmna nk reverse blk..hehe..cthnye backup 1 partition linux pastu nk extract blk

2 | shakir

October 31st, 2007 at 2:31 pm

Avatar

just tukar *if* ngan *of* ajelah

sudo dd if=/media/usbdisk/herugrim-sda6-20071010.img of=/dev/sda6

Make sure the image file is not any bigger than the partition’s size or it might overwrite your next partition’s data

3 | izlan

November 2nd, 2007 at 2:49 pm

Avatar

TemperatureReadEvent,1191036795.878820,2007-09-29 11:33:15,,142,00173b00115eb27a,node6-6lowpan,77.3
TemperatureReadEvent,1191037095.882040,2007-09-29 11:38:15,,148,00173b00115eb27a,node6-6lowpan,77.4
TemperatureReadEvent,1191037395.889310,2007-09-29 11:43:15,,154,00173b00115eb27a,node6-6lowpan,77.5
TemperatureReadEvent,1191037695.932600,2007-09-29 11:48:15,,160,00173b00115eb27a,node6-6lowpan,77.5

kalo ada 4 line ni camne nk extract no yg blakang saje?

kalo cat TemperatureReadEvent.txt | tr “,” ” ” | cut -d ” ” -f9

77.3
77.4
77.5
77.5

kalo nk amik line pertama je cmne? :)

4 | shakir

November 3rd, 2007 at 7:26 am

Avatar

pipe je ke head..

bla2 | head -n 1

Comment Form


  • si perda: wah.. boleh kasi need for speed test power skali... boleh layan network race ni...
  • Faiz: wah....harganya berapa?
  • shakir: Hmm, I have no lab and that actually was my living room :D Sure I'll move them to one of my available rooms at home and make it a lab, but that'll be
  • peja: whoaaa..at least u have ur own lab...look interesting!
  • Qing Ru: He looks really cute! Fatherhood must have been quite rewarding :)
  • shakir: Chris: Thanks, I've updated the post.
  • shakir: tak cukup banyak guinea pig yang dah try and comment on the wimax service, and so I'll just wait :D
  • shakir: Vadim: Yup, but I prefer to just install dosbox and play the game rather than re-installing my system with 32 bit Linux :D
  • Vadim: 2shakir: wine doesn't support 64-bit linux. You have to use 32-bit linux if you want to use wine.
  • kevler: yerp ...dalam 2 hari nih jer ..aku dah kesan 2 BMW X6 , kat puchong dan jalan ampang ..giler laa lawa



Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my own personal opinion. Inappropriate comments will be deleted at the authors discretion. All code samples (if any, ever) are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Personal (Blogs) - TOP.ORG