dd

dd copies data from one place to another, a block at a time, and can transform the data as it goes. It is the tool for low-level copying — writing a disk image to a device, extracting an exact byte range out of a file, copying from or to a raw device.

dd [operand]...
$ dd if=disk.img of=/dev/mydisk bs=4M status=progress

How dd is told what to do #

dd does not take options in the usual -x form. It takes operands, each written name=value, in any order. With no if= operand it reads from standard input; with no of= operand it writes to standard output.

The operands #

OperandMeaning
if=FILERead input from FILE.
of=FILEWrite output to FILE.
bs=BYTESRead and write BYTES at a time. Sets both the input and output block size at once.
ibs=BYTESInput block size (default 512).
obs=BYTESOutput block size (default 512).
cbs=BYTESConversion block size — used by the block and unblock conversions.
count=NStop after N input blocks, rather than reading to the end.
skip=NSkip N input blocks before copying. Also spelled iseek=N.
seek=NSkip N output blocks before writing. Also spelled oseek=N.
conv=LISTApply the comma-separated conversions below.
iflag=LISTComma-separated input flags — how the input is opened and read.
oflag=LISTComma-separated output flags — how the output is opened and written.
status=LEVELHow much to report: progress (periodic stats while copying), noxfer (final counts only), none (silent).

A size value accepts a unit suffix (K, M, G, …). So bs=4M is four mebibytes per block.

Conversions (conv=) #

ValueEffect
ucase / lcaseConvert the data to upper-case / lower-case.
swabSwap every adjacent pair of bytes.
syncPad each input block out to its full size — with zeros, or with spaces alongside block/unblock.
block / unblockConvert between newline-terminated lines and fixed-size cbs records.
sparseWhere an output block is all zeros, seek past it instead of writing it.
exclFail if the output file already exists.
nocreatFail if the output file does not already exist.
notruncDo not truncate the output file when opening it.
noerrorContinue past read errors instead of stopping.
fdatasync / fsyncFlush the data — or the data and metadata — to storage before finishing.

When dd creates the output file — an of= file that does not already exist — the new file needs a security descriptor, and it inherits one from the directory it is created in.

Input and output flags (iflag=, oflag=) #

FlagApplies toEffect
count_bytesinputInterpret count=N as a number of bytes, not blocks.
skip_bytesinputInterpret skip=N as a number of bytes.
fullblockinputWait for a full ibs of data on each read.
seek_bytesoutputInterpret seek=N as a number of bytes.
appendoutputOpen the output in append mode.
directbothUse direct I/O, bypassing the cache.
dsync / syncbothUse synchronised I/O — for data, or for data and metadata.
nonblockbothUse non-blocking I/O.
noatimebothDo not update the file's access time.
nocachebothAsk the system to drop the file's cached pages.
directorybothFail unless the file is a directory.

What dd prints #

Unless status=none is set, dd prints a summary when it finishes:

16+0 records in
16+0 records out
67108864 bytes (67 MB, 64 MiB) copied, 1.234 s, 54.4 MB/s

The records in / records out counts are written complete+partial — full-sized blocks plus any short final block. status=progress prints the last line periodically during a long copy.

Exit status #

CodeMeaning
0The copy completed.
1The copy failed — a bad operand, an I/O error, or a file that could not be opened.

Edit this page