It happens to everybody: You make a small mistake, and there go all your holiday pictures. Luckily, all memory cards and cameras share a few features: JPG files on FAT/FAT32. This makes it especially easy to recover deleted files using standard tools on Linux.

Key points to remember:

  • Once the disaster is a reality, keep the card away from both computer and camera.
  • Do not work with card directly, but instead make an image copy. See below.
  • If you don't have it already, install the forensic tool foremost.
    yum install foremost
  • Before you start, make sure the card is not mounted.

The commands:

umount /media/disk
dd if=//dev/sdb1 of=/tmp/card.img bs=4096 conv=sync,notrunc
mkdir /tmp/recover
foremost -v -t jpg -i /tmp/card.img -o /tmp/recover