How to Securely Wipe a Hard Drive Using the dd Command in Linux

When you are ready to sell, donate, or recycle an old Linux computer, simply formatting the hard drive or deleting the partitions is not enough to protect your privacy. Standard deletion methods only remove the file index, leaving the actual data physically intact on the drive. Anyone with freely available data recovery software can easily retrieve your personal files, financial documents, and saved passwords.

To ensure your data is permanently destroyed and completely unrecoverable, you must overwrite every single block of the storage drive. While there are specialised tools available, you can achieve a military-grade data wipe using nothing but the built-in dd command from the Ubuntu terminal.

Identifying the Target Drive

The dd command is incredibly powerful and entirely unforgiving. It will blindly overwrite whatever drive you point it at without asking for confirmation. Therefore, it is absolutely critical that you correctly identify the drive you intend to wipe before running any destructive commands.

  1. Open your terminal window.
  2. Type lsblk and press Enter. This command lists all storage devices currently connected to your system.
  3. Carefully review the output. You will see drives listed as sda, sdb, nvme0n1, etc., along with their respective partitions (e.g., sda1, sda2) and sizes.
  4. Identify the main drive identifier (such as sdb) based on its total storage capacity. Make absolutely sure you do not select the drive where your current operating system is installed (usually indicated by the / mount point).

Wiping the Drive with Zeros

The fastest way to securely wipe a drive is to overwrite the entire disk with zeros. For most modern drives and everyday users, a single pass of zeros is sufficient to prevent data recovery.

  1. Once you are 100% certain of the target drive identifier (for this example, we will use /dev/sdb), type the following command:
    sudo dd if=/dev/zero of=/dev/sdb bs=4M status=progress
  2. Let’s break down this command:
    • if=/dev/zero sets the input file to a continuous stream of zeros.
    • of=/dev/sdb sets the output file to your target drive. Replace sdb with your actual drive identifier.
    • bs=4M sets the block size to 4 Megabytes, which speeds up the write process significantly compared to the default.
    • status=progress provides a live update of the wiping speed and progress.
  3. Press Enter and provide your administrator password. The process will begin immediately. Depending on the size and speed of the drive, this can take several hours to complete.

The Paranoia Option: Wiping with Random Data

If you are disposing of highly sensitive corporate or government data, writing zeros might not meet strict compliance standards. In these cases, you can instruct dd to overwrite the drive with completely random cryptographic data instead.

  1. The command is almost identical, but you change the input source from /dev/zero to /dev/urandom.
  2. Type:
    sudo dd if=/dev/urandom of=/dev/sdb bs=4M status=progress
  3. Press Enter. Writing random data requires your CPU to actively generate the randomness, meaning this method will be significantly slower than writing zeros. However, it provides the absolute highest level of data destruction possible via software.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.