The DD command we mentioned here is part of the GNU File Utilities. It’s one of the original Unix utilities and should be in everyone’s toolbox. It’s widely used to write disk headers, boot records, and similar system data areas. Misuse of dd has probably trashed many hard disks and file systems.
Like most well-behaved commands, dd reads from its standard input and writes to its standard output, unless a command line specification has been given. Unlike most commands, dd uses a keyword=value format for its parameters. This was reputedly modeled after IBM System/360 JCL, which had an elaborate DD ‘Dataset Definition’ specification for I/O devices. The following section is about a listing of all keywords for the command dd.
Let’s start by a common command:
dd if=/dev/sda of=/dev/sdb bs=1GB
It’ll use one gigabyte block sizes to dump /dev/sda to another harddisk /dev/sdb.
bs=4b would give dd a block size of 4 disk sectors. 1 sector=512 bytes. bs=4k would indicate dd use a 4 kilobyte block size. It’s proven that bs=4k is the fastest for copying disk drives on modern machines. Blocks and bytes may be followed by the following multiplicative suffixes: c 1, w 2, b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024.
Let’s go with all possible dd operands first. In the end of this post, we list some system environment variables that may affect DD’s behaviours. During the next few days, I would create another post on common usage examples for command DD.
DD COMMAND OPERANDS
Let’s be quick and smart as most of these operands are also available in dd’s manual page. The following operands are supported by dd:
if=file – Specifies the input path. Standard input is the default.
of=file – Specifies the output path. Standard output is the default. seek=blocks Skip this many blocks in the output file.
ibs=n – Specifies the input block size in n bytes (default is 512).
obs=n – Specifies the output block size in n bytes (default is 512).
If no conversion other than sync, noerror, and, notrunc is specified, each input block is copied to the output as a single block without aggregating short blocks.
cbs=n – Specifies the conversion block size for block and unblock in bytes by n (default is 0). If cbs= is omitted or given a value of 0, using block or unblock produces unspecified results. This option is used only if ASCII or EBCDIC conversion is specified.
ascii and asciib – operands, the input is handled as described for the unblock operand except that characters are converted to ASCII before the trailing SPACE characters are deleted.
ebcdic, ebcdicb, ibm, and ibmb – operands, the input is handled as described for the block operand except that the characters are converted to EBCDIC or IBM EBCDIC after the trailing SPACE characters are added.
files=n – Copies and concatenates n input files before terminating (makes sense only where input is a magnetic tape or similar device).
skip=n – Skips n input blocks (using the specified input block size) before starting to copy. On seekable files, the implementation reads the blocks or seeks past them. On non-seekable files, the blocks are read and the data is discarded.
iseek=n – Seeks n blocks from beginning of input file before copying (appropriate for disk files, where skip can be incredibly slow).
oseek=n – Seeks n blocks from beginning of output file before copying.
seek=n – Skips n blocks (using the specified output block size) from beginning of output file before copying. On non-seekable files, existing blocks are read and space from the current end-of-file to the specified offset, if any, is filled with null bytes. On seekable files, the implementation seeks to the specified offset or reads the blocks as described for non-seekable files.
count=n – Copies only n input blocks.
conv=value – [,value. . . ] Where values are comma-separated symbols from the following list:
conv=notrunc – Tells dd not to abbreviate blocks of all zero value, or multiple adjacent blocks of zeroes, with five asterisks (when you want to maintain size) Do not use notrunc for copying a larger volume to a smaller volume.
ascii – Converts EBCDIC to ASCII.
asciib – Converts EBCDIC to ASCII using BSD-compatible character translations.
ebcdic – Converts ASCII to EBCDIC. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
ebcdicb – Converts ASCII to EBCDIC using BSD-compatible character translations. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
ibm – Slightly different map of ASCII to EBCDIC. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
ibmb – Slightly different map of ASCII to EBCDIC using BSD-compatible character translations. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd conv=unblock beforehand.
ascii (or asciib), ebcdic (or ebcdicb), and ibm (or ibmb) – values are mutually exclusive. block Treats the input as a sequence of NEWLINE-terminated or EOF-terminated variable-length records independent of the input block boundaries. Each record is converted to a record with a fixed length specified by the conversion block size. Any NEWLINE character is removed from the input line. SPACE characters are appended to lines that are shorter than their conversion block size to fill the block. Lines that are longer than the conversion block size are truncated to the largest number of characters that will fit into that size. The number of truncated lines is reported. unblock Converts fixed-length records to variable length. Reads a number of bytes equal to the conversion block size (or the number of bytes remaining in the input, if less than the conversion block size), delete all trailing SPACE characters, and append a NEWLINE character. The block and unblock values are mutually exclusive.
lcase – Maps upper-case characters specified by the LC_CTYPE keyword tolower to the corresponding lower-case character. Characters for which no mapping is specified are not modified by this conversion.
ucase – Maps lower-case characters specified by the LC_CTYPE keyword toupper to the corresponding upper-case character. Characters for which no mapping is specified are not modified by this conversion. The lcase and ucase symbols are mutually exclusive.
swab – Swaps every pair of input bytes. If the current input record is an odd number of bytes, the last byte in the input record is ignored.
noerror – Does not stop processing on an input error. When an input error occurs, a diagnostic message is written on standard error, followed by the current input and output block counts in the same format as used at completion. If the sync conversion is specified, the missing input is replaced with null bytes and processed normally. Otherwise, the input block will be omitted from the output. notrunc Does not truncate the output file. Preserves blocks in the output file not explicitly written by this invocation of dd.
sync – Pads every input block to the size of the ibs= buffer, appending null bytes. If either block or unblock is also specified, appends SPACE characters, rather than null bytes.
SYSTEM ENVIRONMENT VARIABLES
The following environment variables affect the messages and errors messages of dd:
LANG – Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
LC_ALL – If set to a non-empty string value, override the values of all the other internationalization variables.
LC_CTYPE – Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single – as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- or lower-case, and the mapping of characters from one case to the other.
LC_MESSAGES – Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.
NLSPATH – Determine the location of message catalogues for the processing of LC_MESSAGES.
NOTICE: The core content in this post is originally created by AwesomeMachine at LinuxQuestions.org. Joseph copied, modifed and republished it here. If you have any questions please raise a forum thread here.