|Previous||Table of Contents||Next|
The external dd command converts and copies files. It can read input from a file or from the standard input. It writes to a file or to standard output. The dd command lets you copy data, from one device to another, that do not have the same block size. For example, you might have a tape that has blocks containing 1024K bytes while your file system has 512-byte blocks. In some cases the cpio and tar commands might fail. You could use dd in front of the appropriate command to extract the data from the tape and convert it to a block size the other commands can understand.
It provides several special services for converting data:
It also provides several services for copying data.
Following is the general format of the dd command.
dd [ option=value ... ]
The following list describes the options and their arguments that may be used to control how dd functions.
|Option||Description of Value|
|bs=n||Sets the input and output block size to n bytes. The bs option overrides the ibs and obs options.|
|cbs=n||Sets the conversion buffer size to n bytes. Applies only to the ASCII/EBCDIC/IBM and (BLOCK/UNBLOCK in BSD) conversions. If you are converting from EBCDIC to ASCII, n bytes of an input block are read into the cbs buffer. Trailing spaces are removed and a new-line is added. The contents of the cbs buffer are then written to the output. If you are converting from ASCII to EBCDIC, an ASCII line is read into the cbs buffer. The new-line is removed and trailing blanks are added to create a block containing n bytes. For example, if you want to convert IBM records containing 132 columns, you specify cbs=132. This causes input blocks to be subdivided into 132-byte sections. These sections are equated to ASCII lines.|
|conv=ascii||Converts EBCDIC input to ASCII output.|
|conv=block||Converts variable length records to fixed length records. You must set obs to desired output block length. This pads records of different lengths with spaces to all be the same length.|
|conv=unblock||Converts fixed length records to variable length records. The ibs must be set but the output records are stripped of all trailing blanks, thus creating variable length records.|
|conv=ebcdic||Converts ASCII input to EBCDIC output.|
|conv=ibm||Converts ASCII to a less common EBCDIC format.|
|conv=lcase||Converts uppercase characters to lowercase characters.|
|conv=ucase||Converts lowercase characters to uppercase characters.|
|conv=swab||Swaps the odd and even byte in each pair of bytes. Useful to switch bytes between systems where one uses high order first and another uses the low order byte first.|
|conv=noerror||If an error occurs dd continues to process. Normally, if there is a problem, dd aborts immediately following the error.|
|conv=sync||Pads each input record with spaces until the ibs buffer is filled.|
|conv=val1, val2,...||Multiple values may be combined on the conv option statement by separating the values with commas. For example,|
|converts the standard input from uppercase to lowercase and converts the characters from EBCDIC to ASCII.|
|count=n||Allows only n blocks of input to be copied.|
|ibs=n||The input block size is set to n bytes. If the ibs option is not specified, a 512-byte block is used.|
|if=file||Specifies file as the input file. If the if option is not specified, the standard input is used.|
|obs=n||The output block size is set to n bytes. If the obs option is not given, a 512-byte block is used.|
|of=file||Specifies file as the output file. If the of option is not used, the standard output is used.|
|seek=n||Seek n blocks forward from the beginning of the output file. This means dd skips over the first n blocks of the output file before it starts to write the data.|
|iseek=n||Seek n blocks forward from the beginning of the input before copying data.|
|oseek=n||Same as seek.|
|skip=n||Skips forward the first n blocks of the input file.|
In the previous options the n count can have a suffix attached to indicate the block size. The suffix may be one of the units listed in the following notations.
|nb||Specifies the block size in increments of 512 bytes. For example, 4b means 4 * 512 which equals 2048 bytes, so the block size is 2048 bytes.|
|nk||Specifies the block size in increments of 1024 bytes.|
|nw||Specifies the block size in increments of 2 bytes (words).|
The dd command has no arguments, although you can use the shell's indirection feature to provide input from a file and output to a file. For example,
dd conv=ascii < EBCDICfile > ASCIIfile
converts the contents of the file named EBCDICfile from EBCDIC format to ASCII format and stores the output in the file named ASCIIfile.
DIAGNOSTICS AND BUGS
After it completes the requested process, the dd command returns the number of full and partial blocks read in and written out.
The BLOCK/UNBLOCK conversions cannot be combined with the ASCII/EBCDIC/IBM conversion options.
Refer to the tr command described in Module 140.
The dd command reads from the standard input and writes to the standard output unless you specify files using options.
The most common use of dd is to copy the entire contents of one device to another device. For example, if you wanted to move a file system from one disk device to another, you could use the dd command. Another use is inputting EBCDIC data in from an IBM Mainframe tape to the UNIX system. For example,
dd if=/dev/mt/rmt0 of=emp.list ibs=1320 cbs=132 conv=lcase,ascii
copies the input from an IBM tape mounted on the /dev/mt/rmt0 device tape drive. The output is placed in the emp.list file. The input is in 132-character records with 10 records per block. dd also converts the input to lowercase and to ASCII.
In this activity you use the dd command to convert an ASCII file to EBCDIC, display the EBCDIC file with the cat command and then convert it back to ASCII, and display the output to your screen. Begin at the shell prompt.
|Previous||Table of Contents||Next|