1.\" $NetBSD: dd.1,v 1.16 2003/08/07 09:05:10 agc 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 November 25, 2001 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 140.Dq 1 , 141i.e. a 142.Dq \&. 143is printed for each block written to the output file. 144.It Xo 145.Sm off 146.Cm conv= 147.Cm value Op \&, Cm value \&... 148.Sm on 149.Xc 150Where 151.Cm value 152is one of the symbols from the following list. 153.Bl -tag -width unblock 154.It Cm ascii , oldascii 155The same as the 156.Cm unblock 157value except that characters are translated from 158.Tn EBCDIC 159to 160.Tn ASCII 161before the 162records are converted. 163(These values imply 164.Cm unblock 165if the operand 166.Cm cbs 167is also specified.) 168There are two conversion maps for 169.Tn ASCII . 170The value 171.Cm ascii 172specifies the recommended one which is compatible with 173.At V . 174The value 175.Cm oldascii 176specifies the one used in historic 177.Tn AT\*[Am]T 178and pre- 179.Bx 4.3 Reno 180systems. 181.It Cm block 182Treats the input as a sequence of newline or end-of-file terminated variable 183length records independent of input and output block boundaries. 184Any trailing newline character is discarded. 185Each input record is converted to a fixed length output record where the 186length is specified by the 187.Cm cbs 188operand. 189Input records shorter than the conversion record size are padded with spaces. 190Input records longer than the conversion record size are truncated. 191The number of truncated input records, if any, are reported to the standard 192error output at the completion of the copy. 193.It Cm ebcdic , ibm , oldebcdic , oldibm 194The same as the 195.Cm block 196value except that characters are translated from 197.Tn ASCII 198to 199.Tn EBCDIC 200after the 201records are converted. 202(These values imply 203.Cm block 204if the operand 205.Cm cbs 206is also specified.) 207There are four conversion maps for 208.Tn EBCDIC . 209The value 210.Cm ebcdic 211specifies the recommended one which is compatible with 212.At V . 213The value 214.Cm ibm 215is a slightly different mapping, which is compatible with the 216.At V 217.Cm ibm 218value. 219The values 220.Cm oldebcdic 221and 222.Cm oldibm 223are maps used in historic 224.Tn AT\*[Am]T 225and pre 226.Bx 4.3 Reno 227systems. 228.It Cm lcase 229Transform uppercase characters into lowercase characters. 230.It Cm noerror 231Do not stop processing on an input error. 232When an input error occurs, a diagnostic message followed by the current 233input and output block counts will be written to the standard error output 234in the same format as the standard completion message. 235If the 236.Cm sync 237conversion is also specified, any missing input data will be replaced 238with 239.Tn NUL 240bytes (or with spaces if a block oriented conversion value was 241specified) and processed as a normal input buffer. 242If the 243.Cm sync 244conversion is not specified, the input block is omitted from the output. 245On input files which are not tapes or pipes, the file offset 246will be positioned past the block in which the error occurred using 247.Xr lseek 2 . 248.It Cm notrunc 249Do not truncate the output file. 250This will preserve any blocks in the output file not explicitly written 251by 252.Nm . 253The 254.Cm notrunc 255value is not supported for tapes. 256.It Cm osync 257Pad the final output block to the full output block size. 258If the input file is not a multiple of the output block size 259after conversion, this conversion forces the final output block 260to be the same size as preceding blocks for use on devices that require 261regularly sized blocks to be written. 262This option is incompatible with use of the 263.Cm bs= Ns Ar n 264block size specification. 265.It Cm swab 266Swap every pair of input bytes. 267If an input buffer has an odd number of bytes, the last byte will be 268ignored during swapping. 269.It Cm sync 270Pad every input block to the input buffer size. 271Spaces are used for pad bytes if a block oriented conversion value is 272specified, otherwise 273.Tn NUL 274bytes are used. 275.It Cm ucase 276Transform lowercase characters into uppercase characters. 277.It Cm unblock 278Treats the input as a sequence of fixed length records independent of input 279and output block boundaries. 280The length of the input records is specified by the 281.Cm cbs 282operand. 283Any trailing space characters are discarded and a newline character is 284appended. 285.El 286.El 287.Pp 288Where sizes are specified, a decimal number of bytes is expected. 289Two or more numbers may be separated by an 290.Dq x 291to indicate a product. 292Each number may have one of the following optional suffices: 293.Bl -tag -width 3n -offset indent -compact 294.It b 295Block; multiply by 512 296.It k 297Kilo; multiply by 1024 (1 KB) 298.It m 299Mega; multiply by 1048576 (1 MB) 300.It g 301Giga; multiply by 1073741824 (1 GB) 302.It t 303Tera; multiply by 1099511627776 (1 TB) 304.It w 305Word; multiply by the number of bytes in an integer 306.El 307.Pp 308When finished, 309.Nm 310displays the number of complete and partial input and output blocks, 311truncated input records and odd-length byte-swapping blocks to the 312standard error output. 313A partial input block is one where less than the input block size 314was read. 315A partial output block is one where less than the output block size 316was written. 317Partial output blocks to tape devices are considered fatal errors. 318Otherwise, the rest of the block will be written. 319Partial output blocks to character devices will produce a warning message. 320A truncated input block is one where a variable length record oriented 321conversion value was specified and the input line was too long to 322fit in the conversion record or was not newline terminated. 323.Pp 324Normally, data resulting from input or conversion or both are aggregated 325into output blocks of the specified size. 326After the end of input is reached, any remaining output is written as 327a block. 328This means that the final output block may be shorter than the output 329block size. 330.Pp 331If 332.Nm 333receives a 334.Dv SIGINFO 335signal 336(see the 337.Ic status 338argument for 339.Xr stty 1 ) , 340the current input and output block counts will 341be written to the standard error output 342in the same format as the standard completion message. 343If 344.Nm 345receives a 346.Dv SIGINT 347signal, the current input and output block counts will 348be written to the standard error output 349in the same format as the standard completion message and 350.Nm 351will exit. 352.Sh EXIT STATUS 353The 354.Nm 355utility exits 0 on success and \*[Gt]0 if an error occurred. 356.Sh SEE ALSO 357.Xr cp 1 , 358.Xr mt 1 , 359.Xr tr 1 360.Sh STANDARDS 361The 362.Nm 363utility is expected to be a superset of the 364.St -p1003.2 365standard. 366The 367.Cm files 368operand and the 369.Cm ascii , 370.Cm ebcdic , 371.Cm ibm , 372.Cm oldascii , 373.Cm oldebcdic 374and 375.Cm oldibm 376values are extensions to the 377.Tn POSIX 378standard. 379