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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       dd — convert and copy a file
13

SYNOPSIS

15       dd [operand...]
16

DESCRIPTION

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

OPTIONS

67       None.
68

OPERANDS

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

STDIN

241       If  no  if= operand is specified, the standard input shall be used. See
242       the INPUT FILES section.
243

INPUT FILES

245       The input file can be any file type.
246

ENVIRONMENT VARIABLES

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

ASYNCHRONOUS EVENTS

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

STDOUT

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

STDERR

286       On completion, dd shall write the number of input and output blocks  to
287       standard  error.  In  the  POSIX  locale the following formats shall be
288       used:
289
290
291           "%u+%u records in\n", <number of whole input blocks>,
292               <number of partial input blocks>
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

CONSEQUENCES OF ERRORS

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

APPLICATION USAGE

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

EXAMPLES

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

RATIONALE

365       The OPTIONS section is listed as ``None'' because there are no  options
366       recognized  by historical dd utilities. Certainly, many of the operands
367       could have been designed to use the Utility  Syntax  Guidelines,  which
368       would  have  resulted in the classic hyphenated option letters. In this
369       version of this volume of POSIX.1‐2017, dd retains its curious JCL-like
370       syntax  due to the large number of applications that depend on the his‐
371       torical implementation.
372
373       A suggested implementation technique for conv=noerror,sync is  to  zero
374       (or  <space>-fill,  if  blocking or unblocking) the input buffer before
375       each read and to write the contents of the input buffer to  the  output
376       even  after an error. In this manner, any data transferred to the input
377       buffer before the error was detected is  preserved.  Another  point  is
378       that  a  failed  read  on  a  regular file or a disk generally does not
379       increment the file offset, and dd must then  seek  past  the  block  on
380       which  the  error  occurred;  otherwise, the input error occurs repeti‐
381       tively. When the input is a magnetic tape, however, the  tape  normally
382       has  passed  the block containing the error when the error is reported,
383       and thus no seek is necessary.
384
385       The default ibs= and obs= sizes are  specified  as  512  bytes  because
386       there  are historical (largely portable) scripts that assume these val‐
387       ues. If they were left unspecified, unusual results could occur  if  an
388       implementation chose an odd block size.
389
390       Historical  implementations of dd used creat() when processing of=file.
391       This makes the seek= operand unusable  except  on  special  files.  The
392       conv=notrunc  feature was added because more recent BSD-based implemen‐
393       tations use open() (without O_TRUNC) instead of creat(), but they  fail
394       to delete output file contents after the data copied.
395
396       The  w  multiplier  (historically meaning word), is used in System V to
397       mean 2 and in 4.2 BSD to mean 4. Since word is inherently non-portable,
398       its use is not supported by this volume of POSIX.1‐2017.
399
400       Standard  EBCDIC  does not have the characters '[' and ']'.  The values
401       used in the table are taken from a common print train that does contain
402       them.  Other  than  those  characters,  the  print train values are not
403       filled in, but appear to provide some of the motivation for the histor‐
404       ical choice of translations reflected here.
405
406       The Standard EBCDIC table provides a 1:1 translation for all 256 bytes.
407
408       The  IBM  EBCDIC  table does not provide such a translation. The marked
409       cells in the tables differ in such a way that:
410
411        1. EBCDIC 0112 ('¢') and 0152 (broken pipe) do not appear in  the  ta‐
412           ble.
413
414        2. EBCDIC  0137  ('¬')  translates  to/from  ASCII 0236 ('^').  In the
415           standard table, EBCDIC 0232 (no graphic) is used.
416
417        3. EBCDIC 0241 ('~') translates to/from  ASCII  0176  ('~').   In  the
418           standard table, EBCDIC 0137 ('¬') is used.
419
420        4. 0255  ('[')  and 0275 (']') appear twice, once in the same place as
421           for the standard table and once in place of  0112  ('¢')  and  0241
422           ('~').
423
424       In net result:
425
426              EBCDIC 0275 (']') displaced EBCDIC 0241 ('~') in cell 0345.
427
428                  That displaced EBCDIC 0137 ('¬') 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 ('¢').
435
436       This  translation,  however,  reflects historical practice that (ASCII)
437       '~' and '¬' were often mapped to each other, as were '[' and  '¢';  and
438       ']' 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> characters are  deleted.  For  the
444       ebcdic  and  ibm  operands,  the  input is handled as described for the
445       block operand except that the characters are converted to EBCDIC or IBM
446       EBCDIC after the trailing <space> characters 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       Section 1.4, Utility Description Defaults, sed, tr
473
474       The  Base  Definitions  volume  of POSIX.1‐2017, Chapter 8, Environment
475       Variables
476
478       Portions of this text are reprinted and reproduced in  electronic  form
479       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
480       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
481       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
482       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
483       event of any discrepancy between this version and the original IEEE and
484       The Open Group Standard, the original IEEE and The Open Group  Standard
485       is  the  referee document. The original Standard can be obtained online
486       at http://www.opengroup.org/unix/online.html .
487
488       Any typographical or formatting errors that appear  in  this  page  are
489       most likely to have been introduced during the conversion of the source
490       files to man page format. To report such errors,  see  https://www.ker
491       nel.org/doc/man-pages/reporting_bugs.html .
492
493
494
495IEEE/The Open Group                  2017                               DD(1P)
Impressum