Basics
dd if=<in> of=<out>
Copy a file or device
bs=<size>
Block size for read and write
count=<n>
Copy only n input blocks
skip=<n>
Skip n blocks of input first
seek=<n>
Skip n blocks of output first
status=progress
Show running transfer stats
status=none
Print only errors
status=noxfer
Hide the final summary
bs=4M
Good default for disks and USB
ibs=<size> obs=<size>
Separate read and write sizes
count=<n>B
Count bytes instead of blocks
skip=<n>B
Skip bytes instead of blocks
kill -USR1 $(pidof dd)
Print stats once, keep copying
watch -n1 kill -USR1 $(pidof dd)
Poll stats on a dd already running
Writing and flushing
conv=fsync
Flush data and metadata at the end
conv=fdatasync
Flush data only at the end
oflag=sync
Synchronous writes, slow and safe
oflag=direct
Bypass the page cache on write
iflag=direct
Bypass the page cache on read
conv=notrunc
Do not truncate the output file
conv=excl
Fail if the output exists
conv=nocreat
Fail if the output is missing
oflag=append conv=notrunc
Append to the output
iflag=fullblock
Fill whole blocks when reading pipes
iflag=nocache oflag=nocache
Drop cached pages after use
Disks and images
lsblk -o NAME,SIZE,MODEL,TRAN,MOUNTPOINT
Identify the target device
dd if=<iso> of=/dev/<usb> bs=4M conv=fsync
status=progress
Write an ISO to a USB stick
dd if=/dev/<disk> of=<disk.img> bs=4M
status=progress
Back up a whole disk
dd if=<disk.img> of=/dev/<disk> bs=4M
conv=fsync
Restore a disk image
dd if=/dev/<disk> bs=4M | gzip >
<disk.img.gz>
Compressed disk image
gunzip -c <disk.img.gz> | dd of=/dev/<disk>
bs=4M
Restore compressed image
dd if=/dev/<disk> of=<mbr.bin> bs=512
count=1
Save the first sector (MBR)
dd if=<mbr.bin> of=/dev/<disk> bs=446
count=1
Restore boot code, keep partitions
dd if=/dev/<part> of=<part.img> bs=4M
Image a single partition
dd if=/dev/<disk> bs=4M | ssh <host> 'dd
of=<disk.img>'
Image a disk over SSH
dd if=<in> bs=4M | pv | dd of=<out> bs=4M
Progress bar through pv
dd if=<disk.img> bs=4M | sha256sum
Hash the image to verify
cmp <iso> /dev/<usb> -n $(stat -c %s
<iso>)
Verify what was written
blockdev --getsize64 /dev/<disk>
Device size in bytes
Wiping and test files
dd if=/dev/zero of=<file> bs=1M count=<n>
File of n MiB zeros
dd if=/dev/zero of=<file> bs=1 count=0
seek=<size>
Sparse file, no data written
dd if=/dev/urandom of=<file> bs=1M
count=<n>
File of random bytes
dd if=/dev/zero of=/dev/<disk> bs=4M
status=progress
Zero a whole disk
dd if=/dev/urandom of=/dev/<disk> bs=4M
status=progress
Overwrite with random data
dd if=/dev/zero of=/dev/<disk> bs=1M count=10
Wipe start of disk (old signatures)
dd if=/dev/zero of=/dev/<disk> bs=1M seek=$((
<MiB> - 10 ))
Wipe the end of the disk
truncate -s <size> <file>
Resize or create a sparse file
Benchmarking and extraction
dd if=/dev/zero of=<file> bs=1G count=1
oflag=direct
Rough write speed
dd if=<file> of=/dev/null bs=1M
Rough read speed
echo 3 | sudo tee /proc/sys/vm/drop_caches
Drop caches before a read test
dd if=<file> of=/dev/null bs=1M iflag=direct
Read speed without the cache
dd if=<in> of=<out> bs=1 skip=<off>
count=<len>
Cut a byte range from a file
dd if=<in> of=<out> bs=<n> skip=1
Drop the first n bytes
dd if=<in> of=<out> bs=1 seek=<off>
conv=notrunc
Patch bytes at an offset