dd is a file copying utility you can use for a lot of useful tasks. I will teach you some of them.

Table of Contents

Backup disks/filesystems

See Backup methods (III): dd / tar.

Wipe partitions/disks

You can wipe a partition (or an entire drive) in a way that will be hard to recover deleted files, by overwriting all space with zeros.

dd if=/dev/zero of=/dev/sdb1
  • This is the basic command. You must kill the process when dd shows that there is no space left on the device. You can specify the device space with bs=<bytes> (read and write up to <bytes> bytes at a time) and count=<n> (copy only <n> input blocks) parameters, so it will terminate automatically.
    dd if=/dev/zero of=/dev/sdb1 bs=1M count=512
    

After this command, you will need to recreate the filesystem (by running mkfs).

# e.g.:
mkfs.vfat -F32 /dev/sdb1

Copy an ISO file to a USB drive

The following command is one of the recommended methods of installing Arch Linux ISO file on a USB. You can use it as an example.

dd bs=4M if=path/to/archlinux-version-x86_64.iso of=/dev/sdx conv=fsync oflag=direct status=progress

Create files with a random content

You can create files with any size to do tests. You can use /dev/random/ to fill these files with random data.

dd if=/dev/random of=some_file bs=1M count=100

Create filesystems inside files

By using /dev/zero you can create files that can contain filesystems inside them.

dd if=/dev/zero of=system.img bs=1M count=512

Once created, you can make a filesystem and mount the file as any other partition:

mkfs.ext4 system.img
mount system.img /mnt/test/

Create a swap file

See Swap: how to set up a swap partition or file.

Test with this online terminal:

If you have any suggestion, feel free to contact me via social media or email.