ddcopy and convert input blocks |
Command |
dd
[bs=
s]
[cbs=
s]
[conv=
conversion]
[count=
n]
[ibs=
s]
[if=
file]
[imsg=
string]
[iseek=
n]
[obs=
s]
[of=
file]
[omsg=
string]
[seek=
n]
[skip=
n]
dd
reads and writes data by blocks, and can convert the data
between formats. dd
is frequently used for devices such as
tapes which have discrete block sizes, or for fast multi-sector reads from disks.
The conversions can accommodate computers that require de-blocking, conversion
to/from EBCDIC and fixed length records.
dd
processes input data as follows:
dd
reads an input block.conv=
sync
and 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.bs=
size and requested no
conversion other than sync
or noerror
,
dd
writes the input block (padded if necessary) to the
output as a single block and omits the remaining steps.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 (with padding if
conv=
sync
is specified). As a result, the
final output block may be shorter than the output block size.bs=
sizesets 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=
sizesets the size of the conversion buffer used by various
conv
options. You specify it in the same way as
bs
.
conv=
conversion[, conversion, ...]specifies conversion method. conversion can be any of the following:
ascii
converts EBCDIC input to ASCII for output. dd
copies cbs
bytes at a time to the conversion buffer,
maps them to ASCII, then strips trailing blanks, adds a newline, and
copies this line to the output buffer.
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,
then padding (with spaces) or truncating the record to the size of the
conversion buffer. dd
reports the number of
truncated records on the standard error. You must specify
cbs=
size with this conversion.
ebcdic
converts ASCII input to EBCDIC for output. dd
copies a line of ASCII to the conversion buffer, discards the newline,
pads it with trailing blanks to cbs
bytes, maps it
to EBCDIC and copies it to the output buffer.
ibm
converts ASCII to a variant of EBCDIC which gives better output on many IBM printers.
lcase
converts uppercase input to lowercase.
noerror
ignores errors on input.
notrunc
does not truncate the output file. If a block is explicitly written,
it replaces the existing block; all other blocks are unchanged. See also
of=
file and
seek=
n.
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
pads any input block shorter than ibs
to that
size with null 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 (or the
number of bytes remaining in the input, if less than the conversion
buffer size), deleting all trailing spaces, and appending a newline
character. You must specify cbs=
size with
this conversion.
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 may 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
).
count=
ncopies only n input blocks to the output.
ibs=
sizesets the input block size to size bytes. Specify this option in
the same way as bs
.
if=
filereads input data from file. If you don't specify this option,
dd
reads data from the standard input.
imsg=
stringdisplays 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, giving you a
chance to change volumes (usually diskettes).
iseek=
nseeks to the nth block of the input file. The distinction
between this and skip
is that iseek
does not read the discarded data; however there are some devices, such as
tape drives and communication lines, on which seeking is not possible, so
only skip
is appropriate.
obs=
sizesets the output block size to size bytes. Specify this option in
the same way as bs
. 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=
filewrites output data to file. If you don't specify this option,
dd
writes data to the standard output.
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=
stringdisplays 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, giving you a chance to change volumes (usually
diskettes).
seek=
ninitially seeks to the nth block of the output file.
skip=
nreads and discards the first n blocks of input.
dd
on diskettes
by matching the dd
parameters to the disk format used. The
input and output block size should be large enough to hold an entire track from
the disk, allowing an entire track to be read in one pass. If the input and
output block size do not match the track size, a number of passes must be made
to complete the operation.
The number of blocks copied to the output is set to the number of tracks on the
disk. For example, a 360K diskette is double sided and has nine sectors per
track. Therefore, there are eighteen 512 byte blocks on each track of the
diskette. The diskette has 40 tracks.
reads all of the information of the diskette. Values suitable for use with common Windows diskette formats are summarized in the following table:dd if=a: bs=18b count=40
Size | Cap. | Command Line |
5.25 | 360K | dd if=a: bs=18b count=40 |
5.25 | 1.2M | dd if=a: bs=30b count=80 |
3.5 | 720K | dd if=a: bs=18b count=80 |
3.5 | 1.44M | dd if=a: bs=36b count=80 |
Table 1: dd
Values for Common PC Diskette Formats
Copies a file to drivedd if=file of=a:
A:
, ignoring any Windows file system on the
diskette. You can put data on a diskette more quickly and densely in this manner.
dd if=c: of=a: omsg='Please put disk %d in drive A'
dd
copies everything from drive C:
to drive
A:
. When the disk in drive A:
is full, the utility
prompts you to put the next disk in the drive and when you press ENTER, it
continues.
Converts 80-byte fixed length EBCDIC card images in 6400 byte input blocks to variable length ASCII lines, 512 bytes to the output block.dd if=in of=out conv=ascii cbs=80 ibs=6400 obs=512
0
Successful completion.
1
Failure due to any of the following:
2
Failure resulting in a usage message, such as:
=
does notA 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 which dd
does not recognize as a block size unit (w
, b
,
k
).
conv=ascii
, conv=ebcdic
, and
conv=ibm
options are x/OPEN extensions to the POSIX
standard. The conv=retry
,
conv=
convfile, iseek
,
imsg
, and omsg
options plus the
w
suffix described in the bs=
option are
all extensions to both the POSIX and x/OPEN standards.
tape