[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Commands Reference, Volume 2

dd Command

Purpose

Converts and copies a file.

Syntax

ddcbs=BlockSize ] [ count=InputBlocks ] [ files=InputFiles ] [ fskip=SkipEOFs ] [ if=InFile ] [ of=OutFile ] [ seek=RecordNumber ] [ skip=SkipInputBlocks ] [ ibs=InputBlockSize ] [ obs=OutputBlockSize ] [ bs=BlockSize ] [ conv= ascii blockebcdicibm unblock ] [ lcase ucase ] [ iblock ] [ noerror ] [ swab ] [ sync ] [ oblock ] [ notrunc ] ]

ddOption=Value ]

Description

The dd command reads the InFile parameter or standard input, does the specified conversions, then copies the converted data to the OutFile parameter or standard output. The input and output block size can be specified to take advantage of raw physical I/O.

Note: The term Block refers to the quantity of data read or written by the dd command in one operation and is not necessarily the same size as a disk block.

Where sizes are specified, a number of bytes is expected. A number ending with w, b, or k specifies multiplication by 2, 512, or 1024 respectively; a pair of numbers separated by an x or an * (asterisk) indicates a product.

Note: The count parameter expects the number of blocks, not the number of bytes, to be copied.

The character-set mappings associated with the conv=ascii and conv=ebcdic flags are complementary operations. These flags map between ASCII characters and the subset of EBCDIC characters found on most workstations and keypunches.

Use the cbs parameter value if specifying any of the block, unblock, ascii, ebcdic, or ibm conversions. If unblock or ascii parameters are specified, then the dd command performs a fixed-length to variable-length conversion. Otherwise it performs a conversion from variable-length to fixed-length. The cbs parameter determines the fixed-length.

Attention: If the cbs parameter value is specified smaller than the smallest input block, the converted block is truncated.

After it finishes, the dd command reports the number of whole and partial input and output blocks.

Notes:
  1. Normally, you need only write access to the output file. However, when the output file is not on a direct-access device and you use the seek flag, you also need read access to the file.
  2. The dd command inserts new-line characters only when converting with the conv=ascii or conv=unblock flags set; it pads only when converting with the conv=ebcdic, conv=ibm, or conv=block flags set.
  3. Use the backup, tar, or cpio command instead of the dd command whenever possible to copy files to tape. These commands are designed for use with tape devices. For more information on using tape devices, see the rmt special file.
  4. The block size values specified with the bs, ibs and obs flags must always be a multiple of the physical block size for the media being used.
  5. When the conv=sync flag is specified, the dd command pads any partial input blocks with nulls. Thus, the dd command inserts nulls into the middle of the data stream if any of the reads do not receive a full block of data (as specified by the ibs flag). This is a common occurence when reading from pipes.
  6. If the bs flag is specified by itself and no conversions other than sync, noerror or notrunc are specified, then the data from each input block will be written as a separate output block; if the read returns less than a full block and sync is not specified, then the resulting output block will be the same size as the input block. If the bs flag is not specified, or a conversion other than sync, noerror or notrunc is specified, then the input will be processed and collected into fullsized output blocks until the end of input is reached.

Flags

bs=BlockSize Specifies both the input and output block size, superseding the ibs and obs flags. The block size values specified with the bs flag must always be a multiple of the physical block size for the media being used.
cbs=BlockSize Specifies the conversion block size for variable-length to fixed-length and fixed-length to variable-length conversions, such as conv=block.
count=InputBlocks Copies only the number of input blocks specified by the InputBlocks variable.
files=InputFiles Copies the number of files specified by the InputFiles variable value of input files before ending (makes sense only where input is a magnetic tape or similar device).
fskip=SkipEOFs Skips past the number of end-of-file characters specified by the SkipEOFs variable before starting to copy; this SkipEOFs variable is useful for positioning on multifile magnetic tapes.
ibs=InputBlockSize Specifies the input-block size; the default is 512 bytes or one block. The block-size values specified with the ibs flag must always be a multiple of the physical block size for the media being used.
if=InFile Specifies the input file name; standard input is the default.
obs=OutputBlockSize Specifies the output-block size; the default is 512 bytes or one block. The block size values specified with the obs flag must always be a multiple of the physical block size for the media being used.
of=OutFile Specifies the output file name; standard output is the default.
seek=RecordNumber Seeks the record specified by the RecordNumber variable from the beginning of output file before copying.
skip=SkipInputBlocks Skips the specified SkipInputBlocks value of input blocks before starting to copy.
conv= Conversion,.... Specifies one or more conversion options. Multiple conversions should be separated by commas. The following list describes the possible options:
ascii Converts EBCDIC to ASCII. This option is incompatible with the ebcdic, ibm, block, and unblock options.
block Converts variable-length records to fixed-length. The length is determined by the conversion block size (cbs). This option is incompatible with the ascii, ebcdic, ibm, and unblock options.
ebcdic Converts ASCII to standard EBCDIC. This option is incompatible with the ascii, ibm, block, and unblock options.
ibm Converts ASCII to an IBM version of EBCDIC. This option is incompatible with the ascii, ebcdic, block, and unblock options.
iblock, oblock Minimize data loss resulting from a read or write error on direct access devices. If you specify the iblock variable and an error occurs during a block read (where the block size is 512 or the size specified by the ibs=InputBlockSize variable), the dd command attempts to reread the data block in smaller size units. If the dd command can determine the sector size of the input device, it reads the damaged block one sector at a time. Otherwise, it reads it 512 bytes at a time. The input block size (ibs) must be a multiple of this retry size. This option contains data loss associated with a read error to a single sector. The oblock conversion works similarly on output.
lcase Makes all alphabetic characters lowercase.
noerror Does not stop processing on an error.
notrunc Does not truncate the output file. Instead, blocks not explicitly written to output are preserved.
ucase Makes all alphabetic characters uppercase.
swab Swaps every pair of bytes.
sync Pads every input block to the ibs value.
unblock Converts fixed-length blocks to variable-length. The length is determined by the conversion block size (cbs). This option is incompatible with the ascii, ebcdic, ibm, and block options.

Exit Status

This command returns the following exit values:

0 The input file was copied successfully.
>0 An error occurred.

Examples

  1. To convert an ASCII text file to EBCDIC, enter:
    dd if=text.ascii of=text.ebcdic conv=ebcdic
    This command converts the text.ascii file to EBCDIC representation, storing the EBCDIC version in the text.ebcdic file.
    Note: When you specify the conv=ebcdic parameter, the dd command converts the ASCII ^ (circumflex) character to an unused EBCDIC character (9A hexadecimal), and the ASCII ~ (tilde) to the EBCDIC ^ (NOT symbol).
  2. To convert the variable-length record ASCII file /etc/passwd to a file of 132-byte fixed-length EBCDIC records, enter:
    dd if=/etc/passwd cbs=132 conv=ebcdic of=/tmp/passwd.ebcdic
  3. To convert the 132-byte-per-record EBCDIC file to variable-length ASCII lines in lowercase, enter:
    dd if=/tmp/passwd.ebcdic cbs=132 conv=ascii of=/tmp/passwd.ascii
  4. To convert the variable-length record ASCII file /etc/passwd to a file of 132-byte fixed-length records in the IBM version of EBCDIC, enter:
    dd if=/etc/passwd cbs=132 conv=ibm of=/tmp/passwd.ibm
  5. To copy blocks from a tape with 1KB blocks to another tape using 2KB blocks, enter:
    dd if=/dev/rmt0 ibs=1024 obs=2048 of=/dev/rmt1
  6. To use the dd command as a filter, enter:
    li -l | dd conv=ucase
    This command displays a long listing of the current directory in uppercase.
    Note: The performance of the dd command and cpio command to the 9348 Magnetic Tape Unit Model 12 can be improved by changing the default block size. To change the block size, use the chdev command in the following way:
    chdev -l Device_name -a block_size=32k
  7. To perform efficient transfers to 3.5-inch 1.4MB diskette using 36 blocks of 512 bytes, enter:
    dd if=Filename of=/dev/rfd0 bs=36b conv=sync

    This command writes the value of the Filename parameter to the diskette device a cylinder at a time. The conv=sync is required when reading from disk and when the file size is not a multiple of the diskette block size. Do not try this if the input to the dd command is a pipe instead of a file, it will pad most of the input with nulls instead of just the last block.

Files

/usr/bin/dd Contains the dd command.

Related Information

The backup command, cp command, cpio command, tar command, tr command.

The rmt special file.

The Backup Overview for System Management in AIX Version 4.3 System Management Guide: Operating System and Devices provides information on using backups and using memory devices.

The Files Overview in AIX Version 4.3 System User's Guide: Operating System and Devices provides information on working with files.


[ Previous | Next | Contents | Glossary | Home | Search ]