dd
Copy and convert data
TLDR
Make a bootable USB drive from an isohybrid file (such as archlinux-xxx.iso) and show the progress
Clone a drive to another drive with 4 MiB block size and flush writes before the command terminates
Generate a file with a specific number of random bytes by using kernel random driver
Benchmark the sequential write performance of a disk
Create a system backup, save it into an IMG file (can be restored later by swapping if and of), and show the progress
SYNOPSIS
dd [OPERAND]...
Common operands include:
if=FILE of=FILE bs=BYTES count=BLOCKS skip=BLOCKS seek=BLOCKS conv=CONV status=STATUS
PARAMETERS
if=FILE
Reads from FILE instead of standard input. If FILE is a device, reads raw data from it.
of=FILE
Writes to FILE instead of standard output. If FILE is a device, writes raw data to it. Be cautious, this can overwrite data.
bs=BYTES
Sets both input and output block size to BYTES. This can significantly optimize transfer speed.
count=BLOCKS
Copies only BLOCKS input blocks. Useful for partial copies or creating files of specific sizes.
skip=BLOCKS
Skips BLOCKS input blocks before starting the copy. This is useful for ignoring headers or initial data.
seek=BLOCKS
Skips BLOCKS output blocks before starting the copy. This allows writing to a specific offset within the output file or device.
conv=CONV
Converts the file according to a comma-separated list of symbols (e.g., notrunc to prevent truncation of output file, noerror to continue on read errors, sync to pad input blocks to bs size, lcase to convert uppercase to lowercase, ucase for lowercase to uppercase).
status=STATUS
Controls information displayed to stderr. Common values are progress (shows transfer progress), noxfer (suppresses final transfer statistics), and none (suppresses all messages).
DESCRIPTION
dd is a powerful, low-level command-line utility used for copying and converting data. It operates on a byte-by-byte basis, allowing precise control over input and output operations. Its primary strength lies in handling raw data streams, making it invaluable for tasks such as creating disk images, restoring backups, zeroing out storage devices, and performing data conversions (e.g., ASCII to EBCDIC). Unlike general-purpose copy commands like cp, dd provides granular control over block sizes, offsets, and data transformations. While extremely versatile, its raw access capabilities also make it notoriously dangerous; a simple typo in parameters can lead to irreversible data loss by overwriting critical system partitions or disks. Users often affectionately refer to it as the "disk duplicator" or, due to its destructive potential, the "data destroyer." It's frequently employed by system administrators and power users for disk forensics, bootable USB creation, and testing I/O performance.
CAVEATS
dd is extremely powerful and potentially destructive. A minor mistake in specifying input or output files (e.g., using a raw disk device like /dev/sda) can lead to irreversible data loss by overwriting critical system files or entire partitions. Always double-check your parameters before execution, especially when working with raw devices. It is not designed for general-purpose file copying like cp; use cp for regular file operations.
COMMON USE CASES
dd is widely used for:
Disk Imaging: Creating a bit-for-bit copy of a partition or entire disk (e.g., dd if=/dev/sda of=/mnt/backup/sda.img bs=4M status=progress).
Creating Bootable USB Drives: Writing an ISO image directly to a USB stick (e.g., dd if=debian.iso of=/dev/sdb bs=4M status=progress).
Zeroing/Wiping Disks: Filling a disk with zeros for security or preparing it for a new filesystem (e.g., dd if=/dev/zero of=/dev/sda bs=4M status=progress).
Creating Files of Specific Size: Generating a large dummy file for testing (e.g., dd if=/dev/zero of=largefile.bin bs=1G count=10).
PERFORMANCE CONSIDERATIONS
The bs (block size) parameter significantly impacts dd's performance. Choosing an appropriate block size (e.g., 4M, 16M, or 64K) can dramatically speed up transfers, especially when dealing with large files or raw disk devices. A too-small block size leads to excessive system calls, while a too-large one might not be handled efficiently by the underlying hardware.
SHOWING PROGRESS
For long-running dd operations, the status=progress operand (available in GNU coreutils versions) is invaluable for monitoring progress. Alternatively, on many systems, you can send a SIGUSR1 signal to a running dd process (e.g., kill -USR1 <pid_of_dd>) to make it print its current transfer statistics to stderr without interrupting the operation.
HISTORY
The dd command originated in the early versions of Unix, developed at Bell Labs. Its name is often said to be an acronym for "disk duplicator" or "data definition" (from IBM's JCL DD statement), though jokingly also referred to as "data destroyer" due to its powerful and potentially dangerous capabilities. It was designed to provide low-level I/O operations and data conversion functionalities, fulfilling a niche where higher-level tools were insufficient. Its core functionality has remained largely consistent over decades, making it a staple in Unix-like operating systems.