dd (write data to devices)

This command is used to write large amounts of data to a device. For example, I sometimes use dd to write an image file to an SD card. This is done as follows:

dd if=your_image.img of=/dev/sdx bs=1M

As you may imagine, if means “input file”, of means “output file”, and bs stands for “block size”. Of course, you need to substitute the device file name of your card reader for /dev/sdx. You should double- and triple-check this, because you're in for a terrible data loss if you write to the wrong device!

This also works the other way round, that is, you can backup the contents of an SD card like this:

dd if=/dev/sdx of=backup.img bs=1M

Have you ever sold a used computer or hard disk? I hope that you didn't just delete your files or reformat the disk, because deleted files may be recoverable even if the disk has been reformatted. The easiest way to wipe a hard drive clean is to fill it with zeros (overwriting any data still present). This can be done with dd:

dd if=/dev/zero of=/dev/sdx bs=1M

The operation may take several hours to complete since it will set every single bit of your hard disk to zero. /dev/zero is an interesting device that outputs nothing but a stream of zeros.

An even more secure way of erasing a hard drive is to populate it with random bits instead of zeros, like this:

dd if=/dev/urandom of=/dev/sdx bs=1M

The device /dev/urandom outputs a random stream of ones and zeros. This is more secure than just using zeros, but it takes longer. If you're not a secret agent, filling your hard drive with zeros before selling it should provide a reasonable degree of security.