# How to recover lost data from an SD card

> Learn how to recover lost or deleted files from an SD card using photorec, a free command line tool you can install with Homebrew and run with sudo.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2025-04-21 | Topics: [Tools](https://flaviocopes.com/tags/tools/) | Canonical: https://flaviocopes.com/how-to-recover-lost-data-from-an-sd-card/

Here’s how I recovered (or tried to) lost data from an SD card.

> As usual I write those posts to remember how, as this is the 2nd time I do this procedure and I always have to search how to do it.

I happened to run into trouble with my photography hobby 2 times and SD cards in the past couple months:

1. an SD card appeared empty on the computer and wasn’t readable anymore from the camera (a camera firmware issue), and I had a few days worth of pictures on it
2. I accidentally deleted a picture I didn’t want to delete, directly on camera, and that was a good picture

There’s a lot of mess when you look for disk recovery, maybe slightly in panic because you lost precious stuff, and many of the things you’ll find are paid options.

[**photorec**](https://www.cgsecurity.org/wiki/photoRec) ([GitHub here](https://github.com/cgsecurity/testdisk)) is a free option, actually it’s free GPL-licensed software, which is even better than “just” free.

It’s a command line tool.

Basically tries to retrieve all data that was stored on an SD card (or another kind of disk storage) even after it was deleted.

In the first case I was able to recover my pictures. In the second case it didn’t work, it was a very different use case, but at least I know I tried.

There’s an [official site with docs](https://www.cgsecurity.org/wiki/photoRec)  and also a complete [documentation in PDF](https://www.cgsecurity.org/testdisk.pdf) available

Download it from [https://www.cgsecurity.org/wiki/TestDisk_Download](https://www.cgsecurity.org/wiki/TestDisk_Download)

On a Mac, install it using [Homebrew](https://flaviocopes.com/homebrew/) using `brew install testdisk` (photorec comes with another tool called `testdisk` used to check disk partitions) and then run it with

```typescript
sudo photorec
```
