dd is extremely useful when working with block and character devices. This program’s sole function is to read from an input file or stream and write to an output file or stream, possibly doing some encoding conversion on the way.
dd copies data in blocks of a fixed size. Here’s how to use
dd with a character device and some common options:
$ dd if=/dev/zero of=new_file bs=1024 count=1
As you can see, the
dd option format differs from the option formats of most other Unix commands; it’s based on an old IBM Job Control Language (JCL) style. Rather than use the dash (
-) character to signal an option, you name an option and set its value to something with the equals (
=) sign. The preceding example copies a single 1024-byte block from /dev/zero (a continuous stream of zero bytes) to new_file.
These are the important
fileThe input file. The default is the standard input.
fileThe output file. The default is the standard output.
sizeThe block size.
ddreads and writes this many bytes of data at a time. To abbreviate large chunks of data, you can use
kto signify 512 and 1024 bytes, respectively. Therefore, the example above could read
sizeThe input and output block sizes. If you can use the same block size for both input and output, use the
bsoption; if not, use
obsfor input and output, respectively.
numThe total number of blocks to copy. When working with a huge file—or with a device that supplies an endless stream of data, such as /dev/zero—you want
ddto stop at a fixed point or you could waste a lot of disk space, CPU time, or both. Use
skipparameter to copy a small piece from a large file or device.
numSkip past the first
numblocks in the input file or stream and do not copy them to the output.
dd is very powerful, so make sure you know what you’re doing when you run it. It’s very easy to corrupt files and data on devices by making a careless mistake. It often helps to write the output to a new file if you’re not sure what it will do.