Jun 15

Recover filesFor the past few months I have been using my Sony Cybershot W80 extensively and taking photos left and right. One of the features that I use is that of creating folders on the memory card. On one such occasion I created a new folder which was for experimenting with the camera options next day.

Once I finished with the experimenting I wanted to delete them, since there were lots of photos deleting them individually did not make any sense so I used the ‘delete all photos in the folder’. The pictures got deleted fine….but as luck may have it the initial few photos were the one which I wanted. So was it all gone for ever??

Well….Google is here…..did a quick round of search and ended up with a quick open source solution to recover media files from a memory card. here is what needs to be done.

  • Install ‘testdisk’ package for your distribution
    The first step which I did was to install a software package named “testdisk”, depending on the distribution you use you should easily be able to find the package.
  • Make an image of the memory card
    The next step is to make an image of your memory card, this is achieved using the ‘dd’ command which comes by default with most distributions, the command you will have to issue is:

    $ dd if=/dev/sda1 of=memory_card.img bs=1024

    In the above command, ‘if’ is the input drive which should be your memory card, ‘of’ is the file name for the image which we are creating, and ‘bs’ is the byte size.

  • Recover files by scanning the image using photorec
    The final step is to use a command provided by testdisk package. The ‘photorec’ command will recover all the JPG and GIF files which were recently deleted from your memory card. The command is very simple:

    $ photorec memory_card.img

    The software will take you through a menu driven interface where you will have to select a few options to get your work done. It is simple and anyone should be able to use it with ease.

So by following the above three simple steps I was able to recover the pictures which I had thought were lost for ever and that to using only free software and on a Linux system. There is one or the other software in a Linux system which will always be there for your requirement but may have been unknown to you, but once you know your requirement you would be amazed at the options that are available, atleast I was blown away. Three cheers to free software and lots of thanks to the developers of ‘testdisk’ and ‘photorec’. Now only if someone would write a proper GUI for this….well I don’t want to be too greedy… ;-)

So I am off to take more photos without having to worry about losing some photos unintentionally when deleting photos from the Cybershot memory card…


Tags: Tags: , , , , , ,


Hits for this post: 6614

19 Responses to “Recover deleted files from Memory card in Linux”

  1. Alec Says:

    Thank you so much for this post. This saved over 500 lost pictures including our trip to the zoo and an entire wedding. (My wife was going to kill me!) The tips here saved me a huge headache and $60 for a commercial product that probably would not have worked half as good.

    Struggles:
    Step 1: installing testdisk in Ubuntu is simple with the command “sudo apt-get install testdisk”

    Step 2: I am not a Linux guru and had issues finding my SD card. Using fdisk -l to list out active cards helped me pinpoint the device to image with dd. I run Ubuntu and my device was located at /dev/mmcblk0p1

    Also when running fdisk -l the listed devices will show you what to place into the bs value of the dd command. You should see a line such as “Units = cylinders of 2162 * 512 = 1106944 bytes” I used the 512 value here in place of the 1024 for my card and it worked great. (Not sure if this is nessecary)

    Step 3: No troubles. I just picked a destination directory and watched my lost pictures appear.

    Thank you again for a life saver of a post.

  2. Nithin Says:

    Thanks Alec. Good to know that this post was helpful to you, and nice to hear you overcome some of the struggles in an easier way. Thanks for the details you have covered.

  3. Kathy McGee Says:

    Will this work with windows for a sony memory card?
    I’m not familiar with Linux. and unfortunately, I accidentally deleted some files from my memory card. There were only a few files deleted, so I really don’t want to have to pay for a program to recover them.

  4. Nithin Says:

    @Kathy: There are several windows based programs which will let you records deleted dat, just do a web search. You may come across some free software which does this. And the technique works in Linux for sony memory card.

  5. ctek Says:

    I cannot believe how easy this was. Thank you so much for taking time to post this.

  6. seb Says:

    Thanks for the post, this helped me too ! I was trying with autopsy first but could not figure out how to get the pictures easily.

  7. cbt Says:

    just +1 on the thanks. Never head of photorec before, but will definitely not forget about it

  8. Justin Says:

    Thank you! Thank you! Just recovered +-600 images using this method, from a memory stick. These photos were taken by a designer in Europe on one of her buying trips…seriously, this procedure just saved my neck…or maybe even my job..hehe

    Thanks you again

  9. Tony Says:

    Many thanks you have saved another 400 photos!

    When using dd if=/dev/sda1 of=memory_card.img bs=1024 you don’t need to enter a drive or directory path as it is created in the one your terminal is running in.

    Tony

  10. Nick Says:

    Why a GUI, only a few commands in CLI…

  11. Pete Says:

    Outstanding, another unexplored utility comes to the rescue. Many thanks for the pointers worked exactly as described, my mother in law will be delighted.

  12. Mihkel Says:

    Thanks a lot for the tip, got back ~300 photos that the camera somehow lost from the memory card.

  13. Jonathan Says:

    This worked beautifully; thanks!

  14. kongon Says:

    This just save my day. Thank you very much! :)

    cheers/k

  15. david Says:

    Thank you. My mother deleted all my chicago trip photos and I was able to recover them using this wonderful application. Free software can be so powerful. Your great tutorial save my day. kudos!!!

  16. el Says:

    Thanks a lot for the tip !
    Worked like a charm for my SD-Card. And I guess it will work for every card/disktype. It restored txt’s, jpgs and .avis for me.

  17. tricqster Says:

    As other people posted here – you saved my pictures as well, thank you. :)
    (actually pictures from SD card which belongs to my parents, and that is even more important)

  18. Sandy Says:

    Nice post. Thanks for sharing these tips.

  19. Mike Says:

    Yeeeeeehaa! What a simple solution! Thanks!!!!