Skip to content
Tutorials Center
My learning

Topics

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.

Terminal
dd if=INPUT of=OUTPUT bs=BYTES count=N

Try it

Bash Block size, count, skip and seek

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.

Bash Conversions and files of exact size

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

Terminal
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, skip and seek count blocks, not bytes. bs=1M skip=4 skips 4 MiB. The iflag=skip_bytes and count_bytes flags switch to bytes.
  • Block size affects speed. The default 512 bytes is slow for big copies; bs=1M or bs=4M is 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, and count then counts short blocks. Add iflag=fullblock when exact sizes matter.
  • Danger: dd does exactly what you say, including of=/dev/sda. A swapped if and of destroys a disk. Check the device with lsblk first and read the command twice.
  • Progress: status=progress shows speed and bytes written; on older versions send SIGUSR1 to the process (kill -USR1 PID).
  • conv=sync pads each short input block with zeros to the block size, which corrupts the tail of ordinary files; use it only with noerror for failing disks.
  • Read and write caches: oflag=direct bypasses the cache, conv=fsync flushes before exiting. Without them, "done" may only mean "queued".
  • Often easier tools: head -c takes the first bytes, truncate makes sparse files, cp copies files. dd earns its place for offsets, devices and exact block control.
  • Random data: dd if=/dev/urandom of=key.bin bs=32 count=1 makes 32 random bytes; the output is of course not reproducible.