LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sorting Photorec results (http://www.linuxquestions.org/questions/linux-newbie-8/sorting-photorec-results-4175436628/)

NotAComputerGuy 11-11-2012 03:55 AM

Sorting Photorec results
 
Hi all,

Is there a quick and easy way of sorting the results of files recovered by Photorec? I'm only after a few types of files from the 30+ folders of 500+ files per folder? Ideally I'd like each file type in a different folder.

Is that fairly simple to achieve? I'm hoping a bash script somehow?

Thanks

catkin 11-11-2012 04:24 AM

For those of us that don't have Photorec but may be able to help, it would be helpful if you posted a short illustrative sample of the Photorec output you want to sort -- or a full output somewhere like pastebin

NotAComputerGuy 11-11-2012 04:36 AM

Hi, a sample should get the point of how it sorts it.

So photorec uses some sort of black magic to recover 'deleted' files, or in my case a SD Card with no partition table. It recovers them into folder like this:
Code:

$ pwd
/home/user/Photorec

$ ls
recup_dir.1  recup_dir.17  recup_dir.24  recup_dir.31  recup_dir.4
recup_dir.10  recup_dir.18  recup_dir.25  recup_dir.32  recup_dir.5
recup_dir.11  recup_dir.19  recup_dir.26  recup_dir.33  recup_dir.6
recup_dir.12  recup_dir.2  recup_dir.27  recup_dir.34  recup_dir.7
recup_dir.13  recup_dir.20  recup_dir.28  recup_dir.35  recup_dir.8
recup_dir.14  recup_dir.21  recup_dir.29  recup_dir.36  recup_dir.9
recup_dir.15  recup_dir.22  recup_dir.3  recup_dir.37
recup_dir.16  recup_dir.23  recup_dir.30  recup_dir.38

In each of the folders, you have a list of files:

So in recup_dir.38 a short selection of files using "ls" is:
Code:

f21331411.txt  f21357080.txt  f21375205.txt  f21380160.jpg  f23113738.java
f21331416.txt  f21358016.jpg  f21375210.txt  f21380224.jpg  f23113740.java
f21331502.txt  f21358111.txt  f21375215.txt  f21380352.jpg  f23114929.java
f21331584.txt  f21358120.txt  f21375220.txt  f21380480.jpg  f23114930.java
f21331925.txt  f21358154.txt  f21375264.txt  f21380544.jpg  f23114932.java
f21331968.jpg  f21358391.txt  f21375808.txt  f21380608.jpg  f23114933.java
f21332096.jpg  f21358399.txt  f21376003.txt  f21380672.jpg  f23114934.java
f21332160.jpg  f21358774.txt  f21376005.txt  f21380736.jpg  f24059928.ini
f21333300.txt  f21358786.txt  f21376007.txt  f21380864.jpg  t21327872.jpg
f21333303.txt  f21358796.txt  f21376015.txt  f21380928.jpg  t21328832.jpg

That's the smallest directory by 200 items, containing 331.

I hope that clarifies my problem a little bit, apologies if it's a little too simple or not complicated enough. I'm not great with computers so it's hard to know what's common knowledge and what's not, I hope I haven't seemed patronising.

unSpawn 11-11-2012 07:16 AM

* If you are certain your SD cards contained only image files with certain extensions then I would backup the results and rerun Photorec with only those specific image file filters enabled.
* For sorting see http://www.cgsecurity.org/wiki/After_Using_PhotoRec

Note the script below looks only at the string after the last dot and it will create directories like /home/user/Photorec/txt, /home/user/Photorec/jpg, etc, etc:
Code:

cd /home/user/Photorec
find /home/user/Photorec/recup_dir*/ -type f | while read ITEM; do
 TARGET=${ITEM//*./}; if [ ! -d "/home/user/Photorec/${TARGET}" ]; then
  mkdir "/home/user/Photorec/${TARGET}"; fi
 mv "${ITEM}" "/home/user/Photorec/${TARGET}"
done


NotAComputerGuy 11-14-2012 04:24 AM

Fantastic, thank you very much for the link and the script.

Unfortunately, I wasn't 100% sure that my photos would not be saved as .jpg, .JPG, .JPEG etc so that's why I just recovered everything. Now I've reused the card I can't re-photorec it, but they're not sorted into a manageable order.

Thanks again :)

unSpawn 11-14-2012 06:45 AM

Quote:

Originally Posted by NotAComputerGuy (Post 4829018)
Now I've reused the card I can't re-photorec it,

For next time remember to make a bit-by-bit copy of the victim drive. That way you have a backup to work on leaving the original intact.


Quote:

Originally Posted by NotAComputerGuy (Post 4829018)
but they're not sorted into a manageable order.

Yes, because once deleted there is no longer any order. BTW if your images contain EXIF data you may be able to at least order them according to image creation time:
Code:

cd /home/user/Photorec
find /home/user/Photorec/recup_dir*/ -type f | while read ITEM; do
 file "${ITEM}" 2>&1|egrep -q "(JPEG|JFIF)" && \
  { RES=($(exiftime "${ITEM}" 2>/dev/null)); [ ${#RES[@]} -eq 4 ] && echo "${ITEM} ${RES[2]} ${RES[3]}"; }
done


NotAComputerGuy 11-14-2012 10:43 AM

Quote:

Originally Posted by unSpawn (Post 4829101)
Yes, because once deleted there is no longer any order.

Sorry, that was a typo. Not was mean to read now. I can manage to go through the photos and arrange them properly.

Thanks :)

kishor joshi 11-06-2013 06:09 AM

Arranging photos recovered by using Photorec
 
Quote:

Originally Posted by NotAComputerGuy (Post 4829325)
Sorry, that was a typo. Not was mean to read now. I can manage to go through the photos and arrange them properly.

Thanks :)

=====================================================================
While using Photorec there is an option for file types to br recorved.
For recovering photos use JPEG file option and disable all other file types.
With this the size of recup directories (in Home folder) will be manageble and home folder will still have memory left.
Creat a new folder - Name it as Photo-rec.
Open folder of recup_dir-1 as a root.
Copy all files from this folder to newly created folder Photo-rec.
open all the folders recup_dir one after another as a root and copy files to newly created folder Photo-rec.
Now you can delet all recup_dir folders,since all recovered photos are in newly created folder Photo-rec.
Install Shotwell from Synaptic or Software Center.
Open Shotwell.Import photos from Photo-rec.While imporing from folder use copy option.
Shotwell will import and make albums in Picture folder.The albums are created Yearwise,having subfolders monthwise and datewise.Shotwell does not import duplicate photos.
The sorting is done in minutes.
Images from web are sored in a seperate folder havig year as 1997 or1998 (earlier year that of Jpeg images recovered of Camera Photos.
I had recently recovered around 16000 photos.
Shotwell had sorted the photos within 10 minitues.


All times are GMT -5. The time now is 02:26 PM.