1.\" $NetBSD: dd.1,v 1.22 2009/03/11 12:43:58 joerg Exp $ 2.\" 3.\" Copyright (c) 1990, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Keith Muller of the University of California, San Diego. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" @(#)dd.1 8.2 (Berkeley) 1/13/94 34.\" 35.Dd April 13, 2007 36.Dt DD 1 37.Os 38.Sh NAME 39.Nm dd 40.Nd convert and copy a file 41.Sh SYNOPSIS 42.Nm 43.Op operands ... 44.Sh DESCRIPTION 45The 46.Nm 47utility copies the standard input to the standard output. 48Input data is read and written in 512-byte blocks. 49If input reads are short, input from multiple reads are aggregated 50to form the output block. 51When finished, 52.Nm 53displays the number of complete and partial input and output blocks 54and truncated input records to the standard error output. 55.Pp 56The following operands are available: 57.Bl -tag -width of=file 58.It Cm bs= Ns Ar n 59Set both input and output block size, superseding the 60.Cm ibs 61and 62.Cm obs 63operands. 64If no conversion values other than 65.Cm noerror , 66.Cm notrunc 67or 68.Cm sync 69are specified, then each input block is copied to the output as a 70single block without any aggregation of short blocks. 71.It Cm cbs= Ns Ar n 72Set the conversion record size to 73.Va n 74bytes. 75The conversion record size is required by the record oriented conversion 76values. 77.It Cm count= Ns Ar n 78Copy only 79.Va n 80input blocks. 81.It Cm files= Ns Ar n 82Copy 83.Va n 84input files before terminating. 85This operand is only applicable when the input device is a tape. 86.It Cm ibs= Ns Ar n 87Set the input block size to 88.Va n 89bytes instead of the default 512. 90.It Cm if= Ns Ar file 91Read input from 92.Ar file 93instead of the standard input. 94.It Cm obs= Ns Ar n 95Set the output block size to 96.Va n 97bytes instead of the default 512. 98.It Cm of= Ns Ar file 99Write output to 100.Ar file 101instead of the standard output. 102Any regular output file is truncated unless the 103.Cm notrunc 104conversion value is specified. 105If an initial portion of the output file is skipped (see the 106.Cm seek 107operand) 108the output file is truncated at that point. 109.It Cm seek= Ns Ar n 110Seek 111.Va n 112blocks from the beginning of the output before copying. 113On non-tape devices, a 114.Xr lseek 2 115operation is used. 116Otherwise, existing blocks are read and the data discarded. 117If the user does not have read permission for the tape, it is positioned 118using the tape 119.Xr ioctl 2 120function calls. 121If the seek operation is past the end of file, space from the current 122end of file to the specified offset is filled with blocks of 123.Tn NUL 124bytes. 125.It Cm skip= Ns Ar n 126Skip 127.Va n 128blocks from the beginning of the input before copying. 129On input which supports seeks, a 130.Xr lseek 2 131operation is used. 132Otherwise, input data is read and discarded. 133For pipes, the correct number of bytes is read. 134For all other devices, the correct number of blocks is read without 135distinguishing between a partial or complete block being read. 136.It Cm progress= Ns Ar n 137Switch on display of progress if 138.Va n 139is set to any non-zero value. 140This will cause a 141.Dq \&. 142to be printed (to the standard error output) for every 143.Va n 144full or partial blocks written to the output file. 145.Sm off 146.It Cm conv= Cm value Op \&, Cm value \&... 147.Sm on 148Where 149.Cm value 150is one of the symbols from the following list. 151.Bl -tag -width unblock 152.It Cm ascii , oldascii 153The same as the 154.Cm unblock 155value except that characters are translated from 156.Tn EBCDIC 157to 158.Tn ASCII 159before the 160records are converted. 161(These values imply 162.Cm unblock 163if the operand 164.Cm cbs 165is also specified.) 166There are two conversion maps for 167.Tn ASCII . 168The value 169.Cm ascii 170specifies the recommended one which is compatible with 171.At V . 172The value 173.Cm oldascii 174specifies the one used in historic 175.Tn AT\*[Am]T 176and pre- 177.Bx 4.3 Reno 178systems. 179.It Cm block 180Treats the input as a sequence of newline or end-of-file terminated variable 181length records independent of input and output block boundaries. 182Any trailing newline character is discarded. 183Each input record is converted to a fixed length output record where the 184length is specified by the 185.Cm cbs 186operand. 187Input records shorter than the conversion record size are padded with spaces. 188Input records longer than the conversion record size are truncated. 189The number of truncated input records, if any, are reported to the standard 190error output at the completion of the copy. 191.It Cm ebcdic , ibm , oldebcdic , oldibm 192The same as the 193.Cm block 194value except that characters are translated from 195.Tn ASCII 196to 197.Tn EBCDIC 198after the 199records are converted. 200(These values imply 201.Cm block 202if the operand 203.Cm cbs 204is also specified.) 205There are four conversion maps for 206.Tn EBCDIC . 207The value 208.Cm ebcdic 209specifies the recommended one which is compatible with 210.At V . 211The value 212.Cm ibm 213is a slightly different mapping, which is compatible with the 214.At V 215.Cm ibm 216value. 217The values 218.Cm oldebcdic 219and 220.Cm oldibm 221are maps used in historic 222.Tn AT\*[Am]T 223and pre 224.Bx 4.3 Reno 225systems. 226.It Cm lcase 227Transform uppercase characters into lowercase characters. 228.It Cm noerror 229Do not stop processing on an input error. 230When an input error occurs, a diagnostic message followed by the current 231input and output block counts will be written to the standard error output 232in the same format as the standard completion message. 233If the 234.Cm sync 235conversion is also specified, any missing input data will be replaced 236with 237.Tn NUL 238bytes (or with spaces if a block oriented conversion value was 239specified) and processed as a normal input buffer. 240If the 241.Cm sync 242conversion is not specified, the input block is omitted from the output. 243On input files which are not tapes or pipes, the file offset 244will be positioned past the block in which the error occurred using 245.Xr lseek 2 . 246.It Cm notrunc 247Do not truncate the output file. 248This will preserve any blocks in the output file not explicitly written 249by 250.Nm . 251The 252.Cm notrunc 253value is not supported for tapes. 254.It Cm osync 255Pad the final output block to the full output block size. 256If the input file is not a multiple of the output block size 257after conversion, this conversion forces the final output block 258to be the same size as preceding blocks for use on devices that require 259regularly sized blocks to be written. 260This option is incompatible with use of the 261.Cm bs= Ns Ar n 262block size specification. 263.It Cm sparse 264If one or more non-final output blocks would consist solely of 265.Dv NUL 266bytes, try to seek the output file by the required space instead of 267filling them with 268.Dv NUL Ns s . 269This results in a sparse file on some file systems. 270.It Cm swab 271Swap every pair of input bytes. 272If an input buffer has an odd number of bytes, the last byte will be 273ignored during swapping. 274.It Cm sync 275Pad every input block to the input buffer size. 276Spaces are used for pad bytes if a block oriented conversion value is 277specified, otherwise 278.Tn NUL 279bytes are used. 280.It Cm ucase 281Transform lowercase characters into uppercase characters. 282.It Cm unblock 283Treats the input as a sequence of fixed length records independent of input 284and output block boundaries. 285The length of the input records is specified by the 286.Cm cbs 287operand. 288Any trailing space characters are discarded and a newline character is 289appended. 290.El 291.El 292.Pp 293Where sizes are specified, a decimal number of bytes is expected. 294Two or more numbers may be separated by an 295.Dq x 296to indicate a product. 297Each number may have one of the following optional suffixes: 298.Bl -tag -width 3n -offset indent -compact 299.It b 300Block; multiply by 512 301.It k 302Kibi; multiply by 1024 (1 KiB) 303.It m 304Mebi; multiply by 1048576 (1 MiB) 305.It g 306Gibi; multiply by 1073741824 (1 GiB) 307.It t 308Tebi; multiply by 1099511627776 (1 TiB) 309.It w 310Word; multiply by the number of bytes in an integer 311.El 312.Pp 313When finished, 314.Nm 315displays the number of complete and partial input and output blocks, 316truncated input records and odd-length byte-swapping blocks to the 317standard error output. 318A partial input block is one where less than the input block size 319was read. 320A partial output block is one where less than the output block size 321was written. 322Partial output blocks to tape devices are considered fatal errors. 323Otherwise, the rest of the block will be written. 324Partial output blocks to character devices will produce a warning message. 325A truncated input block is one where a variable length record oriented 326conversion value was specified and the input line was too long to 327fit in the conversion record or was not newline terminated. 328.Pp 329Normally, data resulting from input or conversion or both are aggregated 330into output blocks of the specified size. 331After the end of input is reached, any remaining output is written as 332a block. 333This means that the final output block may be shorter than the output 334block size. 335.Pp 336If 337.Nm 338receives a 339.Dv SIGINFO 340signal 341(see the 342.Ic status 343argument for 344.Xr stty 1 ) , 345the current input and output block counts will 346be written to the standard error output 347in the same format as the standard completion message. 348If 349.Nm 350receives a 351.Dv SIGINT 352signal, the current input and output block counts will 353be written to the standard error output 354in the same format as the standard completion message and 355.Nm 356will exit. 357.Sh EXIT STATUS 358The 359.Nm 360utility exits 0 on success and \*[Gt]0 if an error occurred. 361.Sh SEE ALSO 362.Xr cp 1 , 363.Xr mt 1 , 364.Xr tr 1 365.Sh STANDARDS 366The 367.Nm 368utility is expected to be a superset of the 369.St -p1003.2 370standard. 371The 372.Cm files 373operand and the 374.Cm ascii , 375.Cm ebcdic , 376.Cm ibm , 377.Cm oldascii , 378.Cm oldebcdic 379and 380.Cm oldibm 381values are extensions to the 382.Tn POSIX 383standard. 384