1DD(P)                      POSIX Programmer's Manual                     DD(P)
2
3
4

NAME

6       dd - convert and copy a file
7

SYNOPSIS

9       dd [operand ...]
10

DESCRIPTION

12       The  dd  utility  shall  copy the specified input file to the specified
13       output file with possible conversions using specific input  and  output
14       block  sizes.  It  shall  read the input one block at a time, using the
15       specified input block size; it shall then process  the  block  of  data
16       actually  returned,  which  could  be  smaller than the requested block
17       size. It shall apply any conversions that have been specified and write
18       the  resulting  data  to  the  output in blocks of the specified output
19       block size. If the bs= expr operand is  specified  and  no  conversions
20       other  than  sync, noerror, or notrunc are requested, the data returned
21       from each input block shall be written as a separate output  block;  if
22       the  read returns less than a full block and the sync conversion is not
23       specified, the resulting output block shall be the  same  size  as  the
24       input  block. If the bs= expr operand is not specified, or a conversion
25       other than sync, noerror, or notrunc is requested, the input  shall  be
26       processed  and collected into full-sized output blocks until the end of
27       the input is reached.
28
29       The processing order shall be as follows:
30
31        1. An input block is read.
32
33        2. If the input block is shorter than the specified input  block  size
34           and  the sync conversion is specified, null bytes shall be appended
35           to the input data up to the specified size.  (If  either  block  or
36           unblock  is  also  specified, <space>s shall be appended instead of
37           null bytes.) The remaining conversions and output shall include the
38           pad characters as if they had been read from the input.
39
40        3. If  the  bs= expr operand is specified and no conversion other than
41           sync or noerror is requested, the resulting data shall  be  written
42           to  the output as a single block, and the remaining steps are omit‐
43           ted.
44
45        4. If the swab conversion is specified, each pair of input data  bytes
46           shall  be  swapped. If there is an odd number of bytes in the input
47           block, the last byte in the input record shall not be swapped.
48
49        5. Any remaining conversions ( block, unblock, lcase, and ucase) shall
50           be  performed.  These  conversions  shall operate on the input data
51           independently of the input blocking;  an  input  or  output  fixed-
52           length record may span block boundaries.
53
54        6. The data resulting from input or conversion or both shall be aggre‐
55           gated into output blocks of the specified size. After  the  end  of
56           input  is reached, any remaining output shall be written as a block
57           without padding if conv= sync is not  specified;  thus,  the  final
58           output block may be shorter than the output block size.
59

OPTIONS

61       None.
62

OPERANDS

64       All  of  the  operands shall be processed before any input is read. The
65       following operands shall be supported:
66
67       if=file
68              Specify the input pathname; the default is standard input.
69
70       of=file
71              Specify the output pathname; the default is standard output.  If
72              the seek= expr conversion is not also specified, the output file
73              shall be truncated before the copy begins  if  an  explicit  of=
74              file operand is specified, unless conv= notrunc is specified. If
75              seek= expr is specified, but conv= notrunc is not, the effect of
76              the copy shall be to preserve the blocks in the output file over
77              which dd seeks, but no other portion of the output file shall be
78              preserved.  (If  the size of the seek plus the size of the input
79              file is less than the previous size of the output file, the out‐
80              put file shall be shortened by the copy.)
81
82       ibs=expr
83              Specify  the  input  block  size,  in bytes, by expr (default is
84              512).
85
86       obs=expr
87              Specify the output block size, in bytes,  by  expr  (default  is
88              512).
89
90       bs=expr
91              Set both input and output block sizes to expr bytes, superseding
92              ibs= and obs=. If no conversion other than  sync,  noerror,  and
93              notrunc  is  specified,  each input block shall be copied to the
94              output as a single block without aggregating short blocks.
95
96       cbs=expr
97              Specify the conversion block size for block and unblock in bytes
98              by  expr  (default is zero). If cbs= is omitted or given a value
99              of zero, using block or unblock produces unspecified results.
100
101       The application shall ensure that this operand is also specified if the
102       conv= operand is specified with a value of ascii, ebcdic, or ibm. For a
103       conv= operand with an ascii value, the input is  handled  as  described
104       for  the  unblock  value, except that characters are converted to ASCII
105       before any trailing <space>s  are  deleted.  For  conv=  operands  with
106       ebcdic  or  ibm values, the input is handled as described for the block
107       value except that the characters are converted to EBCDIC or IBM EBCDIC,
108       respectively, after any trailing <space>s are added.
109
110       skip=n Skip  n  input  blocks  (using  the  specified input block size)
111              before starting to copy. On seekable files,  the  implementation
112              shall  read the blocks or seek past them; on non-seekable files,
113              the blocks shall be read and the data shall be discarded.
114
115       seek=n Skip n blocks (using the specified output block size)  from  the
116              beginning  of  the  output  file before copying. On non-seekable
117              files, existing blocks shall be read and space from the  current
118              end-of-file  to  the  specified offset, if any, filled with null
119              bytes; on seekable files, the implementation shall seek  to  the
120              specified  offset  or read the blocks as described for non-seek‐
121              able files.
122
123       count=n
124              Copy only n input blocks.
125
126       conv=value[,value ...]
127
128              Where values are  comma-separated  symbols  from  the  following
129              list:
130
131       ascii
132              Convert EBCDIC to ASCII; see ASCII to EBCDIC Conversion .
133
134       ebcdic
135              Convert ASCII to EBCDIC; see ASCII to EBCDIC Conversion .
136
137       ibm
138              Convert ASCII to a different EBCDIC set; see ASCII to IBM EBCDIC
139              Conversion .
140
141
142       The ascii, ebcdic, and ibm values are mutually-exclusive.
143
144       block
145              Treat the input as a sequence of <newline>-terminated or end-of-
146              file-terminated variable-length records independent of the input
147              block boundaries. Each record shall be  converted  to  a  record
148              with a fixed length specified by the conversion block size.  Any
149              <newline> shall be removed from the input line;  <space>s  shall
150              be  appended  to  lines  that  are shorter than their conversion
151              block size to fill the block. Lines that  are  longer  than  the
152              conversion  block  size shall be truncated to the largest number
153              of characters that fit into that size; the number  of  truncated
154              lines shall be reported (see the STDERR section).
155
156              The block and unblock values are mutually-exclusive.
157
158       unblock
159              Convert  fixed-length  records to variable length. Read a number
160              of bytes equal to the conversion block size (or  the  number  of
161              bytes  remaining in the input, if less than the conversion block
162              size), delete all trailing <space>s, and append a <newline>.
163
164       lcase
165              Map uppercase  characters  specified  by  the  LC_CTYPE  keyword
166              tolower  to  the  corresponding lowercase character.  Characters
167              for which no mapping is specified shall not be modified by  this
168              conversion.
169
170              The lcase and ucase symbols are mutually-exclusive.
171
172       ucase
173              Map lowercase characters specified by the LC_CTYPE keyword toup‐
174              per to the corresponding uppercase  character.   Characters  for
175              which no mapping is specified shall not be modified by this con‐
176              version.
177
178       swab
179              Swap every pair of input bytes.
180
181       noerror
182              Do not stop processing on an input error. When  an  input  error
183              occurs, a diagnostic message shall be written on standard error,
184              followed by the current input and output  block  counts  in  the
185              same  format  as used at completion (see the STDERR section). If
186              the sync conversion is specified, the  missing  input  shall  be
187              replaced  with null bytes and processed normally; otherwise, the
188              input block shall be omitted from the output.
189
190       notrunc
191              Do not truncate the output file. Preserve blocks in  the  output
192              file  not  explicitly written by this invocation of the dd util‐
193              ity. (See also the preceding of= file operand.)
194
195       sync
196              Pad every input block to the size of the ibs= buffer,  appending
197              null  bytes.  (If  either  block  or  unblock is also specified,
198              append <space>s, rather than null bytes.)
199
200
201
202       The behavior is unspecified if operands other than conv= are  specified
203       more than once.
204
205       For  the bs=, cbs=, ibs=, and obs= operands, the application shall sup‐
206       ply an expression specifying a size in bytes. The expression, expr, can
207       be:
208
209        1. A positive decimal number
210
211        2. A  positive decimal number followed by k, specifying multiplication
212           by 1024
213
214        3. A positive decimal number followed by b, specifying  multiplication
215           by 512
216
217        4. Two or more positive decimal numbers (with or without k or b) sepa‐
218           rated by x, specifying the product of the indicated values
219
220       All of the operands are processed before any input is read.
221
222       The following two tables display the octal number character values used
223       for the ascii and ebcdic conversions (first table) and for the ibm con‐
224       version (second table). In both tables, the ASCII values  are  the  row
225       and  column  headers and the EBCDIC values are found at their intersec‐
226       tions. For example, ASCII 0012 (LF) is the second  row,  third  column,
227       yielding  0045 in EBCDIC. The inverted tables (for EBCDIC to ASCII con‐
228       version) are not shown, but are in one-to-one correspondence with these
229       tables.   The  differences  between  the  two tables are highlighted by
230       small boxes drawn around five entries.
231
232                          Table: ASCII to EBCDIC Conversion
233
234
235                        Table: ASCII to IBM EBCDIC Conversion
236

STDIN

238       If no if= operand is specified, the standard input shall be  used.  See
239       the INPUT FILES section.
240

INPUT FILES

242       The input file can be any file type.
243

ENVIRONMENT VARIABLES

245       The following environment variables shall affect the execution of dd:
246
247       LANG   Provide  a  default value for the internationalization variables
248              that are unset or null. (See  the  Base  Definitions  volume  of
249              IEEE Std 1003.1-2001,  Section  8.2,  Internationalization Vari‐
250              ables for the precedence of internationalization variables  used
251              to determine the values of locale categories.)
252
253       LC_ALL If  set  to a non-empty string value, override the values of all
254              the other internationalization variables.
255
256       LC_CTYPE
257              Determine the locale for  the  interpretation  of  sequences  of
258              bytes  of  text  data as characters (for example, single-byte as
259              opposed to multi-byte characters in arguments and input  files),
260              the  classification of characters as uppercase or lowercase, and
261              the mapping of characters from one case to the other.
262
263       LC_MESSAGES
264              Determine the locale that should be used to  affect  the  format
265              and  contents  of  diagnostic messages written to standard error
266              and informative messages written to standard output.
267
268       NLSPATH
269              Determine the location of message catalogs for the processing of
270              LC_MESSAGES .
271
272

ASYNCHRONOUS EVENTS

274       For  SIGINT,  the  dd  utility  shall interrupt its current processing,
275       write status information to standard error, and exit as  though  termi‐
276       nated  by  SIGINT. It shall take the standard action for all other sig‐
277       nals; see  the  ASYNCHRONOUS  EVENTS  section  in  Utility  Description
278       Defaults .
279

STDOUT

281       If  no of= operand is specified, the standard output shall be used. The
282       nature of the output depends on the operands selected.
283

STDERR

285       On completion, dd shall write the number of input and output blocks  to
286       standard  error.  In  the  POSIX  locale the following formats shall be
287       used:
288
289
290              "%u+%u records in\n", <number of whole input blocks>,
291                  <number of partial input blocks>
292
293
294              "%u+%u records out\n", <number of whole output blocks>,
295                  <number of partial output blocks>
296
297       A partial input block is one for which read() returned  less  than  the
298       input  block  size. A partial output block is one that was written with
299       fewer bytes than specified by the output block size.
300
301       In addition, when there is at least one truncated block, the number  of
302       truncated  blocks  shall  be  written  to  standard error. In the POSIX
303       locale, the format shall be:
304
305
306              "%u truncated %s\n", <number of truncated blocks>, "record" (if
307                  <number of truncated blocks> is one) "records" (otherwise)
308
309       Diagnostic messages may also be written to standard error.
310

OUTPUT FILES

312       If the of= operand is used, the output shall be the same  as  described
313       in the STDOUT section.
314

EXTENDED DESCRIPTION

316       None.
317

EXIT STATUS

319       The following exit values shall be returned:
320
321        0     The input file was copied successfully.
322
323       >0     An error occurred.
324
325

CONSEQUENCES OF ERRORS

327       If  an  input error is detected and the noerror conversion has not been
328       specified, any partial output block shall  be  written  to  the  output
329       file,  a  diagnostic  message  shall be written, and the copy operation
330       shall be discontinued. If some other error is  detected,  a  diagnostic
331       message shall be written and the copy operation shall be discontinued.
332
333       The following sections are informative.
334

APPLICATION USAGE

336       The  input  and output block size can be specified to take advantage of
337       raw physical I/O.
338
339       There are many different versions of the EBCDIC codesets. The ASCII and
340       EBCDIC conversions specified for the dd utility perform conversions for
341       the version specified by the tables.
342

EXAMPLES

344       The following command:
345
346
347              dd if=/dev/rmt0h  of=/dev/rmt1h
348
349       copies from tape drive 0 to tape drive 1,  using  a  common  historical
350       device naming convention.
351
352       The following command:
353
354
355              dd ibs=10  skip=1
356
357       strips the first 10 bytes from standard input.
358
359       This  example  reads  an  EBCDIC  tape  blocked ten 80-byte EBCDIC card
360       images per block into the ASCII file x:
361
362
363              dd if=/dev/tape of=x ibs=800 cbs=80 conv=ascii,lcase
364

RATIONALE

366       The OPTIONS section is listed as "None" because there  are  no  options
367       recognized  by historical dd utilities. Certainly, many of the operands
368       could have been designed to use the Utility  Syntax  Guidelines,  which
369       would  have  resulted in the classic hyphenated option letters. In this
370       version of this volume of IEEE Std 1003.1-2001, dd retains its  curious
371       JCL-like  syntax due to the large number of applications that depend on
372       the historical implementation.
373
374       A suggested implementation technique for conv= noerror, sync is to zero
375       (or  <space>-fill,  if  blocking or unblocking) the input buffer before
376       each read and to write the contents of the input buffer to  the  output
377       even  after an error. In this manner, any data transferred to the input
378       buffer before the error was detected is  preserved.  Another  point  is
379       that  a  failed  read  on  a  regular file or a disk generally does not
380       increment the file offset, and dd must then  seek  past  the  block  on
381       which  the  error  occurred;  otherwise, the input error occurs repeti‐
382       tively. When the input is a magnetic tape, however, the  tape  normally
383       has  passed  the block containing the error when the error is reported,
384       and thus no seek is necessary.
385
386       The default ibs= and obs= sizes are  specified  as  512  bytes  because
387       there  are historical (largely portable) scripts that assume these val‐
388       ues. If they were left unspecified, unusual results could occur  if  an
389       implementation chose an odd block size.
390
391       Historical implementations of dd used creat() when processing of= file.
392       This makes the seek= operand unusable  except  on  special  files.  The
393       conv= notrunc feature was added because more recent BSD-based implemen‐
394       tations use open() (without O_TRUNC) instead of creat(), but they  fail
395       to delete output file contents after the data copied.
396
397       The  w  multiplier  (historically meaning word), is used in System V to
398       mean 2 and in 4.2 BSD to mean 4. Since word is inherently non-portable,
399       its use is not supported by this volume of IEEE Std 1003.1-2001.
400
401       Standard  EBCDIC  does not have the characters '[' and ']' . The values
402       used in the table are taken from a common print train that does contain
403       them.  Other  than  those  characters,  the  print train values are not
404       filled in, but appear to provide some of the motivation for the histor‐
405       ical choice of translations reflected here.
406
407       The Standard EBCDIC table provides a 1:1 translation for all 256 bytes.
408
409       The  IBM  EBCDIC  table does not provide such a translation. The marked
410       cells in the tables differ in such a way that:
411
412        1. EBCDIC 0112 ( 'cent' ) and 0152 (broken pipe) do not appear in  the
413           table.
414
415        2. EBCDIC 0137 ( 'not' ) translates to/from ASCII 0236 ( '^' ). In the
416           standard table, EBCDIC 0232 (no graphic) is used.
417
418        3. EBCDIC 0241 ( '~' ) translates to/from ASCII 0176 ( '~' ).  In  the
419           standard table, EBCDIC 0137 ( 'not' ) is used.
420
421        4. 0255  ( '[' ) and 0275 ( ']' ) appear twice, once in the same place
422           as for the standard table and once in place of 0112 ( 'cent' )  and
423           0241 ( '~' ).
424
425       In  net  result:  EBCDIC  0275 ( ']' ) displaced EBCDIC 0241 ( '~' ) in
426       cell 0345.
427
428           That displaced EBCDIC 0137 ( 'not' ) in cell 0176.
429
430           That displaced EBCDIC 0232 (no graphic) in cell 0136.
431
432           That replaced EBCDIC 0152 (broken pipe) in cell 0313.
433
434       EBCDIC 0255 ( '[' ) replaced EBCDIC 0112 ( 'cent' ).
435
436       This translation, however, reflects historical  practice  that  (ASCII)
437       '~' and 'not' were often mapped to each other, as were '[' and 'cent' ;
438       and ']' and (EBCDIC) '~' .
439
440       The cbs operand is required if any of the ascii, ebcdic, or  ibm  oper‐
441       ands  are  specified.  For  the  ascii operand, the input is handled as
442       described for the unblock operand except that characters are  converted
443       to  ASCII  before the trailing <space>s are deleted. For the ebcdic and
444       ibm operands, the input is handled as described for the  block  operand
445       except  that the characters are converted to EBCDIC or IBM EBCDIC after
446       the trailing <space>s are added.
447
448       The block and unblock keywords are from historical BSD practice.
449
450       The consistent use of  the  word  record  in  standard  error  messages
451       matches  most  historical practice. An earlier version of System V used
452       block, but this has been updated in more recent releases.
453
454       Early proposals only allowed two numbers separated by x to be used in a
455       product  when  specifying  bs=,  cbs=,  ibs=,  and obs= sizes. This was
456       changed to reflect the historical practice of allowing multiple numbers
457       in  the  product  as provided by Version 7 and all releases of System V
458       and BSD.
459
460       A change to the swab conversion is required to match  historical  prac‐
461       tice and is the result of IEEE PASC Interpretations 1003.2 #03 and #04,
462       submitted for the ISO POSIX-2:1993 standard.
463
464       A change to the handling of SIGINT  is  required  to  match  historical
465       practice  and is the result of IEEE PASC Interpretation 1003.2 #06 sub‐
466       mitted for the ISO POSIX-2:1993 standard.
467

FUTURE DIRECTIONS

469       None.
470

SEE ALSO

472       Utility Description Defaults , sed , tr
473
475       Portions of this text are reprinted and reproduced in  electronic  form
476       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
477       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
478       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
479       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
480       event of any discrepancy between this version and the original IEEE and
481       The Open Group Standard, the original IEEE and The Open Group  Standard
482       is  the  referee document. The original Standard can be obtained online
483       at http://www.opengroup.org/unix/online.html .
484
485
486
487IEEE/The Open Group                  2003                                DD(P)
Impressum