dd Command Guide for Converting and Copying Raw Data
dd copies data block by block between files and devices, converting as it goes — the tool for disk images, bootable USB sticks, and low-level backups, and the one command most likely to destroy your data by accident.
What is dd, and Why Use It?
dd reads raw data from an input (if=) and writes it to an output (of=), optionally converting along the way. It doesn’t understand “files” the way your shell does — it sees streams of bytes — which is exactly why it can image an entire disk, write an ISO to a USB stick, or clone a partition byte for byte.
dd answers the question “can I get these exact bytes from here to there?” — with a large warning label attached.
Why Learn dd?
- Writing disk images: burning an OS ISO to a USB drive or SD card.
- Imaging whole disks or partitions for backups, forensics, or recovery.
- Cloning a disk onto an equal-or-larger replacement.
- Benchmarking raw throughput of disks and networks.
dddoes not ask questions, and it has no undo. Swapif=andof=and it will happily overwrite your home directory with zeros. Re-read the command line before every run, and usestatus=progressso you can see what’s happening.
1. Copy a File Block by Block
dd if=source.iso of=copy.iso bs=4M
if=is the input file,of=is the output file, andbs=sets the block size. Bigger blocks mean fewer read/write calls and much faster copies —4Mis a good default for images.
Example:
dd if=notes.txt of=notes-backup.txt bs=1M
2. Write a Disk Image to a USB Drive or SD Card
lsblk
dd if=ubuntu-24.04.iso of=/dev/sdb bs=4M status=progress oflag=sync
lsblk(ordiskutil liston macOS) shows device names — the USB stick is usually/dev/sdbor/dev/sdcon Linux,/dev/disk4on macOS.- Point
of=at the whole device (/dev/sdb), not a partition (/dev/sdb1) — writing to a partition corrupts the partition table. status=progressprints live progress;oflag=syncflushes all writes before you pull the stick.- One wrong letter here is irreversible. Triple-check the device before pressing Enter.
3. Image an Entire Disk or Partition
sudo dd if=/dev/sda of=backup-sda.img bs=16M status=progress
sudois required to read raw devices.- The result is a byte-for-byte image you can write back later, or mount with a loop device to inspect.
- Use
if=/dev/sda1to image a single partition instead of the whole disk. - Imaging a mounted, in-use filesystem produces an inconsistent snapshot — unmount it, or boot from a live USB first.
4. Clone a Disk to Another Disk
sudo dd if=/dev/nvme0n1 of=/dev/nvme1n1 bs=16M status=progress conv=fsync
- Device-to-device copy: the target must be at least as large as the source’s used area.
conv=fsyncforces a full flush beforeddexits, so the clone is complete when the prompt returns.- This overwrites everything on the target — there is no confirmation prompt.
5. Copy Only Part of a File
dd if=big.iso of=chunk.iso bs=1M skip=100 count=50
skip=Nskips the first N input blocks;count=Nstops after N blocks. Withbs=1Mthis copies the 100–150 MB range.- Pair with
seek=Nwhen writing into an existing file at an offset.
6. Zero Out a Disk or File
dd if=/dev/zero of=/dev/sdX bs=16M status=progress
/dev/zerois an endless stream of zero bytes; writing it to a device erases everything on it.- This destroys all data on the target with no recovery path. Re-read the
of=path twice. - A smaller variant is useful for creating test files:
dd if=/dev/zero of=sparse.img bs=1M count=100makes a 100 MB file of zeros.
7. Test Raw Disk Throughput
dd if=/dev/zero of=/tmp/testfile bs=1M count=1024 oflag=direct
- Writes 1 GiB of zeros and prints the achieved speed in the summary line (which goes to stderr).
oflag=directbypasses the cache so the number reflects the real device, not RAM. - To test reads instead:
dd if=/dev/sda of=/dev/null bs=1M count=1024 iflag=direct.
8. Verify What dd Wrote
cmp original.iso copy.iso
cmpstops at the first differing byte;md5sumorsha256sumcompare whole-file hashes. For images, this is the difference between “I think it worked” and “I know it worked”.
Common Pitfalls
- Swapping
if=andof=is the classic fatal mistake.ddwill overwrite the input with the output without complaint. Re-read the command before running it. - Device vs. partition.
/dev/sdbis the whole disk;/dev/sdb1is one partition. Writing an image to the wrong one can destroy the partition table. - Reported speeds include caching. Without
oflag=direct/iflag=direct(orconv=fsync),ddcan report gigabytes per second that are really just RAM. - Failing disks need
conv=noerror,sync.noerrorkeeps going past read errors;syncpads the short reads so block offsets stay aligned. - macOS and BSD
dddiffer slightly: block suffixes are lowercase (bs=4m), and GNU-only flags likestatus=progressdon’t exist there.
Related Commands
| Command | Description |
|---|---|
| cmp | Verify the copy byte by byte |
| scp | Network copies when dd’s raw approach isn’t needed |
| du | Check how big an image is growing |
dd Cheatsheet
| Command | What It Does |
|---|---|
dd if=in of=out bs=4M | Copy a file block by block |
dd if=image.iso of=/dev/sdX bs=4M status=progress | Write an ISO to a USB stick |
sudo dd if=/dev/sda of=backup.img bs=16M | Image a whole disk |
sudo dd if=/dev/sda of=/dev/sdb bs=16M conv=fsync | Clone one disk to another |
dd if=in of=out bs=1M skip=100 count=50 | Copy a slice of a file |
dd if=/dev/zero of=f bs=1M count=100 | Create a 100 MB zero-filled file |
dd if=/dev/zero of=/dev/sdX bs=16M | Wipe a device (destroys everything) |
dd if=/dev/zero of=t bs=1M count=1024 oflag=direct | Benchmark raw write speed |
dd if=/dev/sda of=/dev/null iflag=direct bs=1M | Benchmark raw read speed |