Format
dd [bs=size]
[cbs=size] [conv=conversion]
[count=n] [ibs=size]
[if=file] [imsg=string]
[iseek=n] [obs=s]
[of=file] [omsg=string]
[seek=n] [skip=n]>
Description
dd reads
and writes data by blocks. It can convert data
between formats. It is frequently used for such devices as tapes that
have discrete block sizes, or for fast multisector reads from disks. dd performs
conversions to accommodate nonprogrammable terminals, which require
deblocking, conversion to and from EBCDIC, and fixed-length records.
dd processes
the input data as follows:
- dd reads an input block.
- If this input block is smaller than the specified input block
size, dd pads it to the specified size with
null bytes. When you also specify a block or unblock conversion, dd uses
spaces instead of null bytes.
- If you specified bs=s and
requested no conversion other than sync or noerror, dd writes
the padded (if necessary) input block to the output as a single block
and omits the remaining steps.
- If you specified the swab conversion, dd swaps
each pair of input bytes. If there is an odd number of input bytes, dd does
not attempt to swap the last byte.
- dd performs all remaining conversions
on the input data independently of the input block boundaries. A
fixed-length input or output record may span these boundaries.
- dd gathers the converted data into output
blocks of the specified size. When dd reaches
the end of the input, it writes the remaining output as a block (without
padding if conv=sync is
not specified). As a result, the final output block might be shorter
than the output block size.
Options
- bs=size
- Sets both input and output block sizes to size bytes.
You can suffix this decimal number with w, b, k,
or x number, to
multiply it by 2, 512, 1024, or number, respectively.
You can also specify size as two decimal
numbers (with or without suffixes) separated by x to indicate
the product of the two values. Processing is faster when ibs and obs are
equal, since this avoids buffer copying. The default block size is 1B. bs=size supersedes
any settings of ibs=size or obs=size.
If you specify bs=size and
you request no other conversions than noerror, notrunc,
or sync, dd writes
the data from each input block as a separate output block; if the
input data is less than a full block and you did not request sync conversion,
the output block is the same size as the input block.
- cbs=size
- Sets the size of the conversion buffer used by various conv options.
- conv=conversion[, conversion,
…]
- conversion can be any one of the following:
- ascii
- Converts
EBCDIC input to ASCII for output; it is provided for compatibility
purposes only.
To copy a file and convert between a shell code
page and ASCII, use iconv, not dd.
- block
- Converts variable-length records to fixed-length records. dd treats
the input data as a sequence of variable-length records (each terminated
by a newline or an EOF character) independent of the block boundaries. dd converts
each input record by first removing any newline characters and then
padding (with spaces) or truncating the record to the size of the
conversion buffer. dd reports the number
of truncated records on standard error (stderr). You must specify cbs=size with
this conversion.
Note: When working with double-byte characters, dd truncates
the record after the last complete double-byte character that will
fit in the conversion buffer. dd then pads
the record with spaces if it is shorter than the conversion buffer
size.
- convfile
- Uses convfile as a translation table if it is not one of
the conversion formats listed here and it is the name of a file of
exactly 256 bytes.
- You can perform multiple conversions at the same time by separating
arguments to conv with commas; however,
some conversions are mutually exclusive (for example, ucase and lcase).
Note: - When you specify one or more of the character set conversions
(ascii, ebcdic, ibm,
or convfile), dd assumes
that all characters are single-byte characters, regardless of the
locale. Do not use these conversions with double-byte character sets.
- When working with DBCS text, dd treats
the input and output files as character strings and handles DBCS characters
correctly (no splitting and retaining of proper shift states). This
happens only if any of the conversion options (block, unblock, ucase,
or lcase) are specified. Otherwise, DBCS
strings can be corrupted with the seek, count,
or iseek processing.
- ebcdic
- Converts ASCII input to EBCDIC for output; it is provided for
compatibility purposes only.
To copy a file and convert between
a shell code page and ASCII, use iconv,
not dd.
- ibm
- Like ebcdic, converts ASCII to EBCDIC;
it is provided for compatibility purposes only.
To copy a file
and convert between code page 01047 (used in the z/OS shell) and
ASCII, use iconv, not dd.
- lcase
- Converts uppercase input to lowercase.
- noerror
- Ignores errors on input.
- notrunc
- Does not truncate the output file. dd preserves
blocks in the output file that it does not explicitly write to.
- swab
- Swaps the order of every pair of input bytes. If the current input
record has an odd number of bytes, this conversion does not attempt
to swap the last byte of the record.
- sync
- Specifies that dd is to pad any input
block shorter than ibs to that size with
NUL bytes before conversion and output. If you also specified block or unblock, dd uses
spaces instead of null bytes for padding.
- ucase
- Converts lowercase input to uppercase.
- unblock
- Converts fixed-length records to variable-length records by reading
a number of bytes equal to the size of the conversion buffer, deleting
all trailing spaces, and appending a newline character. You must specify cbs=size with
this conversion.
- count=n
- Copies only n input blocks to the output.
- ibs=size
- Sets the input block size in bytes.
You specify it in the same way as with the bs option.
- if=file
- Reads input data from file. If you
don't specify this option, dd reads data
from standard input (stdin).
- imsg=string
- Displays string when all data has been
read from the current volume, replacing all occurrences of %d in string with
the number of the next volume to be read. dd then
reads and discards a line from the controlling terminal.
- iseek=n
- seeks to the nth block of the input
file. The distinction between this and the skip option
is that iseek does not read the discarded
data. There are some devices, however, such as tape drives and communication
lines, on which seeking is not possible, so only skip is
appropriate.
- obs=size
- Sets the output block size in bytes.
You specify it in the same way as the bs value.
The size of the destination should be a multiple of the value chosen
for size. For example, if you choose obs=10K,
the destination's size should be a multiple of 10K.
- of=file
- Writes output data to file. If you
don't specify this option, dd writes data
to standard output (stdout). dd truncates
the output file before writing to it, unless you specified the seek=n operand.
If you specify seek=n,
but do not specify conv=notrunc, dd preserves
only those blocks in the output file over which it seeks. If the size
of the seek plus the size of the input file is less than the size
of the output file, this can result in a shortened output file.
- omsg=string
- Displays string when dd runs
out of room while writing to the current volume. Any occurrences of %d in string are
replaced with the number of the next volume to be written. dd then
reads and discards a line from the controlling terminal.
- seek=n
- Initially seeks to the nth block of
the output file.
Note: Use caution when working with DBCS characters
and the seek option. Seeking into the output
file that contains DBCS characters can cause the DBCS string in the
output file to be corrupted. Be sure that the seek count is not aligned
with an existing DBCS string in the output file. Otherwise, part
of the existing DBCS string either is written over with single-byte
data or has extra shift codes from the input file's DBCS data.
- skip=n
- Reads and discards the first n blocks of input.
Examples
Entering:
dd if=in of=out conv=ascii cbs=80 ibs=6400 obs=512
converts 80-byte fixed-length EBCDIC card images in 6400-byte input
blocks to variable-length ASCII lines, 512 bytes to the output block.
Localization
dd uses
the following localization environment variables:
- LANG
- LC_ALL
- LC_CTYPE
- LC_MESSAGES
- NLSPATH
See Localization for more
information.
Exit values
- 0
- Successful completion
- 1
- Failure due to any of the following:
- I/O errors on read/write
- Incorrect command-line option
- Incorrect arguments to a conversion
- 2
- Failure resulting in a usage message such as:
- An option that should contain = does
not
- Unknown or incorrect command-line option
Messages
Possible error messages include:
- badly formed number number
- A value specified as a number (for example, a block size) does
not have the form of a number as recognized by dd.
For example, you may have followed the number with a letter that dd does
not recognize as a block-size unit (w, b, k).
Portability
POSIX.2, X/Open Portability Guide, UNIX systems.
The conv=convfile, iseek, imsg,
and omsg options plus the w suffix
described in the bs= option are all extensions
of the POSIX standard.
Related information
cp, cpio, iconv, mv, tr