← All commands
THE COMMAND REFERENCE

dd

Copy bytes from an input to an output, with control over block sizes and conversion.

Last updated

Portable / common

Implementation-level reference; examples are not certified for every installed version.

Overview

dd copies data from an input to an output in blocks you choose, and can skip bytes, stop after a number of blocks, and convert case or other things on the way. It is used to make exact copies of devices and to cut pieces out of a file. Its syntax is unusual: arguments are written as name=value, with no dashes. It prints a summary of what it copied on standard error.

Background

A dd command appeared in Version 5 AT&T UNIX, according to the macOS manual, which also says it is expected to be a superset of POSIX.2. Today the name covers GNU dd, the dd that macOS ships, and the dd applet in BusyBox. They agree on if=, of=, bs=, count= and skip=.

Examples

Copy the first three bytes from standard input; 2>/dev/null hides the summary that dd prints on standard error:

printf abcdef | dd bs=3 count=1 2>/dev/null

Skip two bytes and copy the next three, with a block size of one byte:

printf abcdef | dd bs=1 skip=2 count=3 2>/dev/null

Copy one file to another with if= (input file) and of= (output file):

dd if=notes.txt of=out.txt 2>/dev/null && head -n 1 out.txt

Copy with a larger block size, which is faster for big files:

dd if=notes.txt of=out.txt bs=4096 2>/dev/null && head -n 1 out.txt

Operands

if=FILE reads from a file instead of standard input. of=FILE writes to a file instead of standard output, replacing it if it exists. bs=N sets the block size in bytes for reading and writing. count=N copies only that many blocks. skip=N skips that many blocks of the input first.

Common mistakes

dd writes where you tell it, and of= can be a disk: mixing up if= and of= with a device can destroy data with no warning and no undo, so check both names twice and never run an of=/dev/... command you do not understand. The summary on standard error is not part of the copy, but it shows up on the screen unless you hide it. dd has no - options, so dd --help is the way to see what GNU supports.

Portability

Only if=, of=, bs=, count= and skip= are in the Common examples. The conversions and the status= operand differ between implementations; the examples that use them are in the GNU and Apple sections. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.