Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

dd - convert and copy a file

&pagelevel(4)&pagelevel

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.


option

if=input_file

Name of input file

of=output_file

Name of output file

ibs=n

Input block size (in bytes)

obs=n

Output block size (in bytes)

bs=n

Input and output block size (in bytes)

cbs=n

Conversion buffer size (in bytes)

skip=n

Skip first n blocks of input file

iseek=n

Seek n blocks from beginning of input file before copying

oseek=n

Seek n blocks from beginning of output file before copying

seek=n

Seek n blocks from beginning of output file before copying

count=n

Copy/convert only first n blocks of input file

conv=value[,value...]

Several values for conv

conv=ascii

Convert from EBCDIC to ASCII

conv=ebcdic

Convert from ASCII to EBCDIC

conv=siemens

Convert from ASCII to Siemens-specific EBCDIC

conv=ibm

Convert from ASCII to IBM-specific EBCDIC

conv=block

Convert newline-terminated records to fixed-length records

conv=unblock

Convert fixed-length records to newline-terminated records

conv=lcase

Convert uppercase letters to lowercase

conv=ucase

Convert lowercase letters to uppercase

conv=swab

Swap every pair of bytes

conv=noerror

Do not stop processing on error

conv=sync

Pad every input block to the number of characters defined in ibs=n

conv=notrunc

Do not truncate the output file


If size arguments are needed for an option, you can specify them as follows:


n means n times 1
n b means n times 512
n k means n times 1024
n w means n times 2
n x m means n times m


if=input_file

In input_file you give the name of the input file from which dd is to read.

if=input_file not specified:
dd reads from standard input.

of=output_file

output_file designates the name of the output file to which dd is to write.

of=output_file not specified:
dd writes to standard output.

ibs=n

(input block size)

In n you specify the input block size in bytes.

ibs=n not specified:
The input block size defaults to 512 bytes.

obs=n

(output block size)

In n you specify the output block size in bytes.

obs=n not specified:
The output block size defaults to 512 bytes.

bs=n

(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.

cbs=n

(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:

  • for conversions from EBCDIC to ASCII and vice versa

  • for conversions from and to fixed-length records.

(see conv=ascii, conv=ebcdic, conv=ibm and conv=block, conv=unblock).

skip=n

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.

iseek=n

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.

oseek=n

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=n

seek performs the same function as oseek.

count=n

Only the first n blocks of the input file are copied (and converted, if specified).

conv=value[,value...]

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.

conv=ascii

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.

conv=ebcdic

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.

conv=siemens

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' .

conv=ibm

Conversion from ASCII to EBCDIC as described above, but using an IBM-specific EBCDIC table.

conv=block

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.

conv=unblock

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.

conv=lcase

Uppercase letters are converted to the corresponding lowercase letters.

conv=ucase

Lowercase letters are converted to the corresponding uppercase letters.

conv=swab

The bytes in each pair of bytes are swapped. If an input block contains an uneven number of bytes, the last byte is ignored.

conv=noerror

Processing is continued even if an error occurs.

conv=sync

Every input block is padded to the value specified in ibs=n. When block or unblock is specified, blanks are used, otherwise null-bytes.

conv=notrunc

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:

$ dd if=/dev/rmt32 of=xy ibs=800 cbs=80 conv=ascii

See also

cp