Deleting files doesn't delete data. Formatting doesn't either — it just marks the space as available. If you're selling a laptop, retiring a server, or recycling an old drive, "deleted" files are usually fully recoverable with free tools. Actually wiping a drive takes a few more steps, and the right method depends on whether it's an old spinning disk or a modern SSD.
First, the non-negotiables: back up anything you need, then double-check the device name. Every command below is irreversible.
Identify the drive
lsblk Match by size, not by order — your system disk is usually sda or nvme0n1. The examples below use /dev/sdX; replace it with your actual device. Getting this wrong wipes the wrong disk.
Method 1: dd — overwrite with zeros (HDD)
sudo dd if=/dev/zero of=/dev/sdX bs=64M status=progress && sync One full pass of zeros defeats normal recovery tools on a modern hard drive. Multiple passes are mostly superstition for drives made this century — the old "35-pass Gutmann wipe" belongs to 1990s hardware. Expect this to take hours on a big disk.
Want pseudorandom data instead? Swap the input: if=/dev/urandom.
Method 2: shred — targeted overwriting (HDD)
shred overwrites a device (or file) multiple times and can zero it at the end:
sudo shred -v -n 1 -z /dev/sdX -n 1 one random pass, -z a final zero pass so the drive looks empty. Same time cost as dd, friendlier output.
Method 3: Secure Erase / blkdiscard — the right way for SSDs
Do not dd an SSD for hours. Flash cells have limited write cycles, and wear-leveling means overwrites may not even touch the old data. Use the drive's built-in sanitize functions instead:
sudo blkdiscard /dev/sdX blkdiscard issues a discard for the whole device, effectively resetting an SSD to its factory-erased state in seconds. On NVMe drives you can also use sudo nvme format /dev/nvmeX -s 1 (crypto-erase/sanitize, where supported).
If the drive is your boot disk, do this from a live USB — you can't erase the system you're running on.
Method 4: DBAN — bootable wiping for old machines
Darik's Boot and Nuke is the classic: boot it from USB, pick the drive, choose a method, walk away. It's still handy for a stack of old HDDs, but it's unmaintained and doesn't understand modern SSD sanitize commands. For SSDs, prefer blkdiscard.
When only destruction will do
If the data is genuinely sensitive and the drive is leaving your control — or it's already failed and won't accept commands — software wiping isn't enough. Physically destroying the platters or flash chips (professional shredding, or a drill through the drive) is the final answer. Encrypting drives from day one makes all of this easier: deleting the encryption key effectively destroys the data instantly.
Verify before you hand it over
After wiping, read a chunk back:
sudo dd if=/dev/sdX bs=1M count=100 | hexdump -C | head You should see zeros (or a clean unformatted device). Then create a fresh partition table if the drive is going back into service. The drive is now safe to sell, donate, or recycle — and your old files are actually gone, not just "deleted."
![Why Object.keys(user) Returns string[], Not (keyof User)[]: TypeScript Means It](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2q4w48b9bzs43tynyhsf.png)

