The dd command can be used to copy files while making any necessary conversions, e.g. from EBCDIC to ASCII or vice versa.
dd is well-suited for input/output via raw devices (raw physical I/O), because it can read and write in blocks of any size. Note, however, that any given raw device can only handle the block sizes for which it is specifically designed (512-byte blocks for a floppy disk drive, for example. If the size of the file you want to convert is not a multiple of the appropriate block size, you must use the conv=sync option.
After completion, dd reports the number of whole and partial input and output blocks on standard error.
Caution!
Never use dd to copy files between file systems which have different block sizes.
Using a block device to copy a file may result in extra nulls being added to the file to pad the final block to the block boundary.
Syntax
dd[ option ...] |
No option specified dd reads from standard input and writes to standard output. No conversions are performed. The input and output block sizes default to 512 bytes.
Name of input file
Name of output file
Input block size (in bytes)
Output block size (in bytes)
Input and output block size (in bytes)
Conversion buffer size (in bytes)
Skip first n blocks of input file
Seek n blocks from beginning of input file before copying
Seek n blocks from beginning of output file before copying
Seek n blocks from beginning of output file before copying
Copy/convert only first n blocks of input file
Several values for conv
Convert from EBCDIC to ASCII
Convert from ASCII to EBCDIC
Convert from ASCII to Siemens-specific EBCDIC
Convert from ASCII to IBM-specific EBCDIC
Convert newline-terminated records to fixed-length records
Convert fixed-length records to newline-terminated records
Convert uppercase letters to lowercase
Convert lowercase letters to uppercase
Swap every pair of bytes
Do not stop processing on error
Pad every input block to the number of characters defined in ibs=n
Do not truncate the output file If size arguments are needed for an option, you can specify them as follows:
In input_file you give the name of the input file from which dd is to read. if=input_file not specified:
output_file designates the name of the output file to which dd is to write. of=output_file not specified:
(input block size) In n you specify the input block size in bytes. ibs=n not specified:
(output block size) In n you specify the output block size in bytes. obs=n not specified:
(block size) In n you specify a value in bytes for both the input and output block size. The value specified for bs overrides the values of ibs and obs.
(conversion buffer size) In n you specify a value in bytes for the conversion buffer size. This specification is only effective in the following cases:
(see conv=ascii, conv=ebcdic, conv=ibm and conv=block, conv=unblock).
The first n blocks of the input file are skipped, and copying begins at block number n+1.This option is only appropriate for magnetic tape, where iseek is undefined.
The first n blocks of the input file are skipped, and copying begins at block number n+1.This option is specially designed for disk files, where skip can be extremely slow. It is only accepted with devices which support the lseek system call (such as disk units). skip and iseek are mutually exclusive.
The copy of the input file (after conversion, if specified) begins n blocks into the output file (i.e. at block n+1). The first n blocks of the output file remain unchanged. This option is only accepted with devices which support the lseek system call (such as disk units).
seek performs the same function as oseek.
Only the first n blocks of the input file are copied (and converted, if specified).
You can specify several comma-separated values for conv and thus have a number of conversions performed. The values ascii, ebcdic and ibm cannot be used in combination. The same applies to the pairs block and unblock, and lcase and ucase.
Conversion from EBCDIC to ASCII. The number of characters defined in cbs=n is copied into the conversion buffer and any specified character mapping is done. Trailing blanks are removed, and a newline character is added. The output block size of the file is thus adjusted to the value defined in cbs=n. If cbs is unspecified or set to 0, input file character mapping is done, but trailing blanks are not removed.
Conversion from ASCII to EBCDIC. The ASCII characters are read into the conversion buffer and converted to EBCDIC. Trailing blanks are added in order to produce the output block size defined in cbs=n. If cbs is unspecified or set to 0, input file character mapping is done, but the file’s block structure is not changed.
Conversion from ASCII to EBCDIC as described above, but by using a Siemens-specific EBCDIC table. The Newline character is converted as follows:: X'0A' <-> X'05' .
Conversion from ASCII to EBCDIC as described above, but using an IBM-specific EBCDIC table.
Conversion of newline-terminated ASCII records to fixed-length records. The ASCII characters are read into the conversion buffer, and blanks are added to adjust the record length or output block size to the value defined in cbs=n. If cbs is unspecified or set to 0, this option produces a simple file copy.
Conversion of fixed-length ASCII records to newline-terminated records. The record length is determined by the value defined in cbs=n. This number of characters is repeatedly read into the conversion buffer, where excess trailing blanks are removed and a newline character is added before the characters are sent to the output. If cbs is unspecified or set to 0, this option produces a simple file copy.
Uppercase letters are converted to the corresponding lowercase letters.
Lowercase letters are converted to the corresponding uppercase letters.
The bytes in each pair of bytes are swapped. If an input block contains an uneven number of bytes, the last byte is ignored.
Processing is continued even if an error occurs.
Every input block is padded to the value specified in ibs=n. When block or unblock is specified, blanks are used, otherwise null-bytes.
The output file is not regenerated. All blocks that are not overwritten explicitly by dd remain unchanged. |
Locale
The following environment variables affect the execution of dd: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization 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- to 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. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example
The contents of an EBCDIC tape with a block structure of 10 times 80 bytes is to be written to the ASCII file xy:
|
See also
cp |