The Linux dd Command

Article by Michael Dougherty (2,770 pts ) , published Jun 14, 2009

The Linux dd command - as useful as it is powerful when used properly. Use caution when using this command, though, or you could end up destroying the information on your hard drive!

Quick Links

A Brief History of dd

The dd command has been around for over 30 years, rewritten numerous times, ported to several different systems, and has withstood the test of time. The dd command is part of the fileutils package on most Linux distributions and, to this day, is an invaluable tool for Linux administrators and users alike.

dd - What does it do?

Disk Definition (dd) came from IBM’s Job Control Language and quickly became one of the more powerful and frequently used low-level UNIX and Linux commands. Data backup is one of the most frequent uses of this powerful command. You can create a byte-exact copy of a partition saving it to file or duplicating it to another hard drive. With the ability to restore this byte-exact copy anytime using the dd command again.

Other uses of the Linux dd command include creating an additional swapfile on a running server, benchmarking your hard drive, safely and securely erasing your hard drive, and much more!

dd - The Syntax

man ddThe dd command uses the outdated if and of statements. You can simply think of it as input file and output file.

dd if=input-file of=output-file

For example:

dd if =/dev/sda of=/dev/sdb

This command would clone the data located on /dev/sda to /dev/sdb. Keep in mind that Linux devices are formatted as /dev/sd*, where * is the letter given to a particular device. This is then followed by a single number signifying the partition on that device. For example:

dd if=/dev/sda3 of=/my-home-directory/mybackupfile.bak

would make a byte-exact clone of your sda3 partition to a file called mybackupfile.bak in your home directory.

A full list of possible dd operands can be found in the dd section of The Open Group Base Specifications Issue 6. In the following sections we will take a look at some common uses of dd.