How to format a USB flash drive with dd

Featured image by Karolina Grabowska via Pexels.

One of my favorite tools on *NIX systems is dd (which stands for copy and convert – “cc” is already taken by the C Compiler). This is a handy utility that allows you to do all sorts of things with drives. When I need to securely erase it, I run a dd command. Additionally, I’ve used it to “fix” flash drives that would refuse to work or format properly under Windows. It’s also just a great way to quickly wipe a questionable flash drive, too (such as one you pick up for free from conferences or events).


First, find your drive:

lsblk -l

Once you have the name of it, let’s make sure it’s unmounted from the system:

umount /dev/sdb

In my example, I’m using sdb, but make sure you replace that with the actual name of your flash drive. Watch what you type because you can destroy your system if you select the wrong disk!

Now we’ll format it with zeros:

sudo dd if=/dev/zero of=/dev/sdb bs=1m

This will take a few minutes to complete, depending on the size of the flash drive.


If you have a Mac, you can also use the dd utility.

To find the name of the disk, use the CLI version of Disk Utility.

diskutil list

Unmount the drive.

diskutil unmountDisk /dev/disk2

Again, in my example, I’m using /dev/disk2 but use your actual disk name. Watch what you type because you can inadvertently damage your system if you select the wrong disk!

sudo dd if=/dev/zero of=/dev/rdisk2 bs=1m

Note the use of rdisk2 here. rdisk will format closer to the actual hardware device and not at the block-level that “disk” will get you.

This will complete after a few minutes, depending on the size of the disk.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.