I am wondering how to wipe an SD card using my Raspberry Pi. The card I am hoping to wipe has had pictures on it from a camera, and I have deleted these. All that remains is the undeletable folder named 'DCIM.' I do not wish to plague my parents with this issue, so is there any way I can wipe this card with my Raspberry Pi? Many thanks to anyone willing to help.

  • 2
    Hello and welcome. You may want to specify clearly what you mean by "wipe". There's a noteworthy distinction between "just" formatting the card or deleting all files and "wipe" in the sense of data erasure, purging a computer file to counter data remanence.
    – Ghanima
    Dec 30, 2015 at 12:47
  • 3
    what is the major problem with this file that is going to plague your parents? Are they really likley to lose sleep over this folder? Dec 30, 2015 at 12:49

4 Answers 4


Using a USB sd card reader, you can.

Using a tool called "fdisk"

  1. First run fdisk -l to identify the correct drive.

  2. Run the following in case the SD card is /dev/sdb

  3. fdisk /dev/sdb

  4. Type d to remove the partition

  5. Type n for a new partition and basically follow the prompts.

More info here


If you have a card reader you can plug it into the USB port and reformat the card using the directions in this question. Note the link I provided gives several alternative methods of formatting an SD card including using a digital camera (not all have this feature).


The link that Steve and Havnar gave have good information, but I have seen where fdisk can get 'confused' if the partition table itself is corrupted, or if a 3rd party partition manager was used on the card (although admittedly, those aren't nearly as common nowadays as they once were).

There is another way of wiping the card completely - including the partition table - albeit it can take a long time. From the terminal session, type these commands:

sudo su -

[[ then enter your password at the prompt ]] this will allow you to become the 'root' user or superuser in linux. You'll need to be root to run the next command, and for the tutorial I'll assume that you have already ascertained that the SD card you want to wipe is /dev/sdb:

dd bs=512 if=/dev/zero of=/dev/sdb

The dd command is a very low-level command in Linux and can basically copy anything to any device. The bs parameter is short for 'byte size' and 512 is usually the sector size for SD cards. if= specifies the 'input file' but this description is a bit misleading as it can be any named pipe, device, etc. It's not limited to files. In this case, you're pulling input from a device that does nothing but return zeroes whenever requested. of= is 'Output File" and again, you're not writing to a file per se, but writing to the raw disk device. So, what this command does is write zeroes to every sector on the card, thereby wiping it.

This command will take a very long time to complete, but when it's done your card will be completely blank. I should also warn you, that the command by default has no output until it has completed, so it might look like it's not doing anything, but it is. More on this below.

Now, if you did have a corrupted partition table but you're not worried about wiping every single sector, usually the first 10k-100k sectors are sufficient to wipe, then repartition the card with fdisk. To only wipe the beginning part of the card, add a parameter to the dd command:

dd bs=512 count=100000 if=/dev/zero of=/dev/sdb

The count= parameter will only copy zeroes to that number of sectors and then will quit. This will be much faster than wiping the full SD card.

As an aside, the dd command is also useful for writing disk images to the SD card. Let's say you just downloaded a newer version of the NOOBS package for your Raspberry Pi. In linux, you can transfer this image to an SD card by this command:

dd if=/home/userdir/Downloads/noobspackagefile.img of=/dev/sdb

Again, assuming that the card you want to write to is mapped as /dev/sdb, and set the directory & name of the downloaded NOOBS image correctly in your if= statement, that will transfer the file sector-by-sector to the SD card that you can then set as your boot device on your Raspberry Pi and boot from it.

Lastly, if you are fully wiping a device in this manner or transferring a large image, there is a way of seeing how far along the process is. In another terminal window, become the superuser again (as outlined above) and type this command:

ps -ax | grep dd

you may get more than one line of output, find the correct line for your dd command and note the number directly on the left. That's the Process ID or pid of your running dd command. Now, type this command:

kill -USR1 #####

where ##### is the Process ID noted above. This will interrupt the dd process just long enough to allow it to output how many bytes/sectors have been transferred since the command was invoked.

  • Be aware: the dd command is a loaded gun with no safety. It will cheerfully do exactly what you ask, including trash your boot drive. Be careful out there. Dec 31, 2015 at 15:05
  • Re ghanima: I have tried inserting the card into the Pi to install an operating system, if this is how it is done? I may be completely wrong and stupid... I was wondering if the DCIM file was affecting this, and if so how to get rid of this file soi can proceed to my initial goal. Dec 31, 2015 at 17:22

This works for any linux,

  1. wipefs /dev/sdcard (replace sdcard with the name of the device) and note the partition table (if any) type and partition type(s)
  2. wipefs -a /dev/sdcard to wipe the partition table (and partitions)
  3. you can then either:
    a) recreate the partition table and partition(s) with a tool such as parted or gparted (runs in X)
    b) run mkfs.fs /dev/sdcard (replace fs with the desired filesystem, I recommend vfat for windows and ext2 for Linux)

Of course, this requires one to have the mkfs utilities and wipefs. I believe both tools are included by default on most distributions. If mkfs.vfat doesn't exist, install it with:

sudo apt-get install dosfstools on Debian (or Raspbian or any other Debian derivative)


pacman -S dosfstools on Archlinux (as root)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.