Linux Command Reference ยท Files and Directories
Linux dd command
Reference for the Linux dd command: copy bytes in blocks, skip and seek, limit with count, convert case, create files of exact size and read the status.
dd copies data from an input to an output in fixed-size blocks, optionally converting it on the way. It reads from a file or standard input (if=) and writes to a file or standard output (of=). Because it works on raw bytes and can start and stop at exact offsets, it is the classic tool for writing disk images, cloning partitions, extracting pieces of binary files and producing files of a given size.
Its syntax is unusual: options are name=value pairs without dashes, a leftover from IBM job control language. Statistics go to standard error, not standard output, so they do not mix with data sent to a pipe.
dd if=INPUT of=OUTPUT bs=BYTES count=N
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
dd [OPERAND=VALUE]...
| Operand | Description |
|---|---|
if=FILE |
Input file (default: standard input). |
of=FILE |
Output file (default: standard output). The file is truncated first unless conv=notrunc. |
bs=N |
Read and write N bytes at a time (sets ibs and obs). Suffixes: K, M, G (1024-based), KB, MB, GB (1000-based). |
ibs=N, obs=N |
Input and output block sizes separately. |
count=N |
Copy only N input blocks. |
skip=N |
Skip N input blocks before copying. |
seek=N |
Skip N output blocks before writing. |
conv=LIST |
Comma-separated conversions: ucase, lcase, swab, notrunc, sync, noerror, fsync, excl, nocreat. |
iflag=FLAGS, oflag=FLAGS |
Open-mode flags such as direct, sync, append, count_bytes, skip_bytes, fullblock. |
status=LEVEL |
none (silent), noxfer (no totals), progress (live updates). |
Returns: 0 on success; non-zero if reading or writing failed. With conv=noerror,sync, read errors are skipped and padded with zeros, and the status can still be 0.
Usage notes
count,skipandseekcount blocks, not bytes.bs=1M skip=4skips 4 MiB. Theiflag=skip_bytesandcount_bytesflags switch to bytes.- Block size affects speed. The default 512 bytes is slow for big copies;
bs=1Morbs=4Mis a common choice for disks. For tiny jobs it does not matter. - Partial reads from pipes: when input comes from a pipe,
read()can return fewer bytes than asked, andcountthen counts short blocks. Addiflag=fullblockwhen exact sizes matter. - Danger:
dddoes exactly what you say, includingof=/dev/sda. A swappedifandofdestroys a disk. Check the device withlsblkfirst and read the command twice. - Progress:
status=progressshows speed and bytes written; on older versions sendSIGUSR1to the process (kill -USR1 PID). conv=syncpads each short input block with zeros to the block size, which corrupts the tail of ordinary files; use it only withnoerrorfor failing disks.- Read and write caches:
oflag=directbypasses the cache,conv=fsyncflushes before exiting. Without them, "done" may only mean "queued". - Often easier tools:
head -ctakes the first bytes,truncatemakes sparse files,cpcopies files.ddearns its place for offsets, devices and exact block control. - Random data:
dd if=/dev/urandom of=key.bin bs=32 count=1makes 32 random bytes; the output is of course not reproducible.
Related
truncate,head,od,shred- Lessons: Binary and hex tools, LVM and file systems