Linux dd Command: Copy and Convert Data by Blocks
This guide explains how to copy and convert files or block devices with Linux dd, choose block sizes and ranges, display progress, verify results, and avoid overwriting the wrong device. It focuses on practical Linux usage, predictable automation, and the cases where a seemingly small path or option mistake can change the result.
The examples use GNU Coreutils behavior. Check dd --help, man dd, and your distribution documentation when portability or a version-specific option matters.
What Is the dd Command?
dd reads input and writes output in blocks while supporting size, offset, conversion, and I/O flags. Its main operands use name=value syntax without spaces around the equals sign. A mistaken of= can immediately overwrite a file or block device.
Basic Syntax
dd [OPERAND]...
Quote paths that contain spaces. When supported, place -- before operands that begin with a hyphen so they are not interpreted as options.
Basic dd Usage
Copy one file to another
if names the input and of names the output. Use cp for ordinary file copies and dd when block-level control is required.
dd if=source.img of=copy.img bs=4M status=progress
Create a fixed-size zero-filled file
Reading from /dev/zero writes real zero data and consumes write bandwidth and allocated space, unlike a sparse truncate operation.
dd if=/dev/zero of=test.bin bs=1M count=100 status=progress
Create a disk image
An image of a live, changing filesystem may be inconsistent. Prefer an unmounted device, a snapshot, or an application-aware backup, and verify the input device identity.
sudo dd if=/dev/sdb of=/backup/disk-sdb.img bs=16M status=progress conv=fsync
Check copy results with a small file instead of a device
dd copies input (if=) to output (of=) in bytes. If you specify the device path incorrectly, you can overwrite data, so first understand how it works with a small regular file.
printf 'ABC' > source.bin dd if=source.bin of=copy.bin bs=1 status=none cmp -s source.bin copy.bin echo $?
Example output 0 means the byte contents of the two files are the same. status=none hides the progress summary of dd. For device image operations, you should separately check the target size, mount status, and backup.
Key Options
| Option | Purpose |
|---|---|
if=FILE |
Select the input file or device. |
of=FILE |
Select the output file or device. |
bs=SIZE |
Set both input and output block size. |
count=N |
Limit the number of input blocks copied. |
skip=N |
Skip input blocks before reading. |
seek=N |
Skip output blocks before writing. |
status=progress |
Periodically display transfer progress. |
conv=noerror,sync |
Continue after read errors and pad short blocks. |
conv=fsync |
Synchronize output data and metadata before finishing. |
iflag=fullblock |
Accumulate short reads to fill input blocks where needed. |
Long options often make reviewed scripts easier to understand. When a script must run on non-GNU systems, verify every non-POSIX option on the target platform.
Practical Examples
Verify a device before restoring an image
Restoring an image overwrites the destination's existing data and partition structures. Confirm model, serial, size, mount state, and direction immediately before execution.
lsblk -o NAME,SIZE,MODEL,SERIAL,FSTYPE,MOUNTPOINTS findmnt sudo dd if=/backup/disk.img of=/dev/sdc bs=16M status=progress conv=fsync
Extract a range from an image
skip and count are measured in the selected input block units. GNU byte-oriented flags may provide finer control when supported.
dd if=disk.img of=segment.bin bs=1M skip=100 count=20 status=progress
Verify copied output
Choose verification proportional to the risk: compare sizes, partition metadata, or checksums, and account for cached writes before disconnecting a device.
sha256sum source.img copy.img stat -c '%s %n' source.img copy.img sync
dd and Related Commands
| Command or method | Primary role | Best fit |
|---|---|---|
dd |
Block-oriented copy and conversion | Images and offset-based work |
cp |
Filesystem-level file copying | Ordinary files and directories |
rsync |
Incremental and remote synchronization | Repeated backups and network copies |
GNU ddrescue |
Retry and map damaged-media reads | Recovering as much as possible from a failing disk |
Important Cautions
Reversing if and of can destroy the source
The of operand is the write target. Recheck the direction and device identity immediately before running the command.
A larger block size is not always better
The best size depends on the device and workload. Very large blocks can increase memory use and make error recovery coarser.
Use a recovery-specific tool for failing media
conv=noerror,sync is limited. GNU ddrescue is designed for retry strategy, progress maps, and resumable recovery.
FAQ
What do if and of mean?
if is the input to read; of is the output to overwrite.
How do I display progress?
Add status=progress with GNU dd.
Should a whole-disk image be written to a partition path?
Often a whole-disk image targets the entire device, but follow the image provider's instructions and verify the target.
Can dd recover a disk with read errors?
It may copy readable data, but GNU ddrescue is usually more suitable for damaged media and resumable recovery.









