# Recovering deleted pictures from SD memory card

It finally happened! I unintentionally deleted all pictures that I took in a month time from my camera's SD memory cards without downloading them first. After the first shock and disbelief, I remembered that deleting them usually means they are just "marked" for overwriting and that they are still there, but not enlisted in the memory card's filesystem.

Luckily, there are helpful free (free as in speech) tools that helped me to recover all of the pictures.

I inserted the ("empty") SD cards into the card reader and run QPhotoRec (which is just a GUI for the command-line tool photorec). With it, I managed to read all deleted files and save them to a different location. Since the information about their names and location is lost permanently, I first filtered all JPG pictures with the original resolution (there were many smaller resolution copies that the camera created as thumbnails), in my case the original resolution is 6000x4000 or 4000x6000:

# find . -type f -name '*;jpg' -exec identify {} ; | awk '{split($3,a,"x"); if (a[1] >= 4000 && a[2] >= 4000) print$1}' | xargs -I{} cp -u {} ../original

Finally, from EXIF I renamed them to something more meaningful (date and time of creation) instead of the gibberish of memory locations following Stack Exchange:

# exiftool -d '%Y%m%d-%H%M%%-03.c.%%e' '-filename<CreateDate' .

That's it.