ArticleslgStudy

computer science

Dd (Unix)

Dd (Unix) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Dd (Unix) rather than just read about it. In short: dd (Data(set) Definition) is a shell command for reading, writing and converting file data. Originally developed for Unix, it has been implemented on many other environments including Unix-like operating systems, Windows, Plan 9 and Inferno.

Key takeaways

  • Dd (Unix) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Dd (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Dd (Unix) from memory before moving on to harder problems.

Reference excerpt

dd (Data(set) Definition) is a shell command for reading, writing and converting file data. Originally developed for Unix, it has been implemented on many other environments including Unix-like operating systems, Windows, Plan 9 and Inferno. The command can be used for many purposes. For relatively simple copying operations, it tends to be slower than domain-specific alternatives, but it excels at overwriting or truncating a file at any point or seeking in a file. The command supports reading and writing files, and if a driver is available to support file-like access, the command can access devices too. Such access is typically supported on Unix-based systems that provide file-like access to devices (such as storage) and special device files (such as /dev/zero and /dev/random). Therefore, the command can be used for tasks such as backing up the boot sector of a drive, and obtaining random data. The command can also support converting data while copying, including byte order swapping and converting between ASCII and EBCDIC text encodings. dd is sometimes humorously called "Disk Destroyer", due to its disk-erasing capabilities involving typos.

History In 1974, the dd command appeared as part of Version 5 Unix. According to Dennis Ritchie, the name is an allusion to the DD statement found in IBM's Job Control Language (JCL), where DD is short for data definition. Explaining the cultural context of its syntax, Douglas McIlroy has remarked that dd was "originally intended for converting files between the ASCII, little-endian, byte-stream world of DEC computers and the EBCDIC, big-endian, blocked world of IBM". Eric S. Raymond believes "the interface design was clearly a prank", due to the command's syntax resembling a JCL statement more than other Unix commands do. In 1987, the dd command is specified in the X/Open Portability Guide issue 2 of 1987. This is inherited by IEEE Std 1003.1-2008 (POSIX), which is part of the Single UNIX Specification. In 1990, David MacKenzie announced GNU fileutils (now part of coreutils) which includes the dd command; it was written by Paul Rubin, David MacKenzie, and Stuart Kemp. Since 1991, Jim Meyering is its maintainer. In 1995, Plan 9 2nd edition was released with a dd command with a more traditional command-line option style than the JCL statement style. Since at least 1999, UnxUtils has provided a native implementation for the Windows platform.

Use The command line interface significantly differs from most modern shell commands in that an option is formatted as option=value instead of the more typical syntax that denotes an option with a dash prefix such as: -x, -y value, --abc, --def value. By default, dd reads from standard input and writes to standard output, but input and output can be overridden. Option if specifies an input file and option of specifies an output file. Non-standardized aspects of dd depend on the underlying system or implementation, including:

Direct memory access Signal handling End-of-file (EOF) handling; in particular the Windows ports vary: Cygwin uses Ctrl+D (the usual for Unix) and MKS Toolkit uses Ctrl+Z (the usual for Windows)

Output messages On completion, dd writes statistics to standard error. The format is standardized in POSIX. The manual page for GNU dd does not describe this format, but the BSD manuals do. Each of the "Records in" and "Records out" lines shows the number of complete blocks transferred + the number of partial blocks, e.g. because the physical medium ended before a complete block was read, or a physical error prevented reading the complete block. If dd receives a SIGINFO signal while it's running – typically triggered by the user pressing Ctrl+T – it writes intermediate statistics to standard error and continues processing.

Block size The command processes data in blocks. The default size is 512 (the POSIX-mandated size and a common legacy size for disk hardware) but can be specified via command-line options. Option bs specifies the size for both input (read) and output (write) operations. Alternatively, option ibs specifies the size for input operations and obs for output operations. Option cbs affects conversion operations. Options count, skip and seek specify a number of blocks: maximum to read, to start reading at offset from the start of the input, and to start writing at offset from the start of the output, respectively. A block size option value is specified as a whole decimal number of bytes with an optional suffix to indicate a multiplier. POSIX requires suffixes b (blocks) for 512 and k (kibibytes) for 1024, but implementations differ on other suffixes. (Free) BSD uses m for mebibytes, g for gibibytes and so on for larger power of two units. GNU uses M and G and so on for these units and uses kB, MB, and GB for SI units. For example, for GNU dd, bs=16M indicates a size of 16 MiB (16777216 bytes) and bs=3kB specifies 3000 bytes. For POSIX compliance, some implementations interpret the x character as a multiplication operator for both block size and count option values. For example, bs=2x80x18b is interpreted as 2 × 80 × 18 × 512 = 1474560 bytes, the size of a 1440 KiB floppy disk. For implementations that do not support this feature, the POSIX shell arithmetic syntax of bs=$((2*80*18))b may be used. Block size affects performance. Many small reads and writes is often slower than fewer, larger ones. On the downside, larger blocks require more RAM and can complicate error recovery. When used with a variable block size device such as a tape drive or a network, the block size may determine the tape record size or network packet size, depending on the network protocol.

Examples The examples below apply to many implementations, but are specifically written for GNU dd. Generally, the only difference between implementations is block size values and can be portable by using shell arithmetic expression instead of a size multiplier suffix. For example, instead of bs=64M use bs=$((64*1024*1024)) or bs=$((64 << 20)).

Data transfer The command can duplicate data across files, devices, partitions and volumes, and it can transform data during transfer as specified via option conv. In some cases, data transfer is faster with cat. To create an ISO disk image from a CD-ROM, DVD or Blu-ray disc:

blocks=$(isosize -d 2048 /dev/sr0) dd if=/dev/sr0 of=isoimage.iso bs=2048 count=$blocks status=progress

To restore a drive from an image file:

To create an image of partition sdb2, using a 64 MiB block size:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Dd (Unix)

Start with the simplest possible case. Write down what Dd (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Dd (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Dd (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Dd (Unix)

In research
Dd (Unix) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Dd (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Dd (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data erasure software, Data recovery software, Disk cloning, so understanding it makes those chapters shorter.
In everyday life
Look for Dd (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Dd (Unix)” →

How to study Dd (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Dd (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Dd (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Dd (Unix) in simple terms?

dd (Data(set) Definition) is a shell command for reading, writing and converting file data. Originally developed for Unix, it has been implemented on many other environments including Unix-like operating systems, Windows, Plan 9 and Inferno.

Why does Dd (Unix) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Dd (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Dd (Unix).

Tags

  • Data erasure software
  • Data recovery software
  • Disk cloning
  • Hard disk software
  • Inferno (operating system) commands
  • Plan 9 commands
  • Standard Unix programs
  • Unix SUS2008 utilities

Keep exploring