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.

Related Resources

More in This Category
Linux tracepath Command: Trace a Network Path and Path MTU

Linux tracepath Command: Trace a Network Path and Path MTU

Learn how to trace a Network Path and Path MTU with the Linux tracepath command, including practical examples, key options, and important precautions.

Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree

Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree

Use pwd, ls, cd, and tree to find your current location, inspect directories, navigate paths, and check where each command takes you.

Linux rsync Command: Synchronize Files and Directories

Linux rsync Command: Synchronize Files and Directories

Learn how to synchronize Files and Directories with the Linux rsync command, including practical examples, key options, and important precautions.

Linux dirname Command: Extract the Directory Part of a Path

Linux dirname Command: Extract the Directory Part of a Path

Learn how to use the Linux dirname command to remove the final component of a path and return its directory portion, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux type Command: Identify How a Command Is Resolved

Linux type Command: Identify How a Command Is Resolved

Learn how to use the Linux type command to identify aliases, functions, built-ins, keywords, and executable paths, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux mv Command: Move and Rename Files and Directories

Linux mv Command: Move and Rename Files and Directories

Learn how to move and rename files or directories with Linux mv, avoid unwanted overwrites, clarify destination paths, and handle cross-filesystem moves.

Linux shutdown Command: Schedule a Shutdown or Restart

Linux shutdown Command: Schedule a Shutdown or Restart

Learn how to schedule a Shutdown or Restart with the Linux shutdown command, including practical examples, key options, and important precautions.

Linux Tutorial / Choosing a Linux Distribution

Linux Tutorial / Choosing a Linux Distribution

Explore major Linux distributions and learn when to choose Ubuntu LTS or Rocky Linux for study and server practice. Compare package management, release policies, and practical selection criteria.

Linux tar Command: Create and Extract Archives

Linux tar Command: Create and Extract Archives

Learn how to create and Extract Archives with the Linux tar command, including practical examples, key options, and important precautions.

Linux find Command: Search Files by Name, Type, Size, and Time

Linux find Command: Search Files by Name, Type, Size, and Time

Learn how to search with Linux find by name, file type, size, and modification time, combine expressions, run commands safely, and verify targets before deletion.