1.\" Copyright (c) 1990, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Keith Muller of the University of California, San Diego. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 4. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)dd.1 8.2 (Berkeley) 1/13/94 32.\" $FreeBSD$ 33.\" 34.Dd March 5, 2004 35.Dt DD 1 36.Os 37.Sh NAME 38.Nm dd 39.Nd convert and copy a file 40.Sh SYNOPSIS 41.Nm 42.Op Ar operands ... 43.Sh DESCRIPTION 44The 45.Nm 46utility copies the standard input to the standard output. 47Input data is read and written in 512-byte blocks. 48If input reads are short, input from multiple reads are aggregated 49to form the output block. 50When finished, 51.Nm 52displays the number of complete and partial input and output blocks 53and truncated input records to the standard error output. 54.Pp 55The following operands are available: 56.Bl -tag -width ".Cm of Ns = Ns Ar file" 57.It Cm bs Ns = Ns Ar n 58Set both input and output block size to 59.Ar n 60bytes, superseding the 61.Cm ibs 62and 63.Cm obs 64operands. 65If no conversion values other than 66.Cm noerror , 67.Cm notrunc 68or 69.Cm sync 70are specified, then each input block is copied to the output as a 71single block without any aggregation of short blocks. 72.It Cm cbs Ns = Ns Ar n 73Set the conversion record size to 74.Ar n 75bytes. 76The conversion record size is required by the record oriented conversion 77values. 78.It Cm count Ns = Ns Ar n 79Copy only 80.Ar n 81input blocks. 82.It Cm files Ns = Ns Ar n 83Copy 84.Ar n 85input files before terminating. 86This operand is only applicable when the input device is a tape. 87.It Cm ibs Ns = Ns Ar n 88Set the input block size to 89.Ar n 90bytes instead of the default 512. 91.It Cm if Ns = Ns Ar file 92Read input from 93.Ar file 94instead of the standard input. 95.It Cm iseek Ns = Ns Ar n 96Seek on the input file 97.Ar n 98blocks. 99This is synonymous with 100.Cm skip Ns = Ns Ar n . 101.It Cm obs Ns = Ns Ar n 102Set the output block size to 103.Ar n 104bytes instead of the default 512. 105.It Cm of Ns = Ns Ar file 106Write output to 107.Ar file 108instead of the standard output. 109Any regular output file is truncated unless the 110.Cm notrunc 111conversion value is specified. 112If an initial portion of the output file is seeked past (see the 113.Cm oseek 114operand), 115the output file is truncated at that point. 116.It Cm oseek Ns = Ns Ar n 117Seek on the output file 118.Ar n 119blocks. 120This is synonymous with 121.Cm seek Ns = Ns Ar n . 122.It Cm seek Ns = Ns Ar n 123Seek 124.Ar n 125blocks from the beginning of the output before copying. 126On non-tape devices, an 127.Xr lseek 2 128operation is used. 129Otherwise, existing blocks are read and the data discarded. 130If the user does not have read permission for the tape, it is positioned 131using the tape 132.Xr ioctl 2 133function calls. 134If the seek operation is past the end of file, space from the current 135end of file to the specified offset is filled with blocks of 136.Dv NUL 137bytes. 138.It Cm skip Ns = Ns Ar n 139Skip 140.Ar n 141blocks from the beginning of the input before copying. 142On input which supports seeks, an 143.Xr lseek 2 144operation is used. 145Otherwise, input data is read and discarded. 146For pipes, the correct number of bytes is read. 147For all other devices, the correct number of blocks is read without 148distinguishing between a partial or complete block being read. 149.It Cm conv Ns = Ns Ar value Ns Op , Ns Ar value ... 150Where 151.Cm value 152is one of the symbols from the following list. 153.Bl -tag -width ".Cm 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.At 178and 179.No pre- Ns 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.At 225and 226.No pre- Ns Bx 4.3 reno 227systems. 228.It Cm lcase 229Transform uppercase characters into lowercase characters. 230.It Cm pareven , parnone , parodd , parset 231Output data with the specified parity. 232The parity bit on input is stripped unless 233.Tn EBCDIC 234to 235.Tn ASCII 236conversions is also specified. 237.It Cm noerror 238Do not stop processing on an input error. 239When an input error occurs, a diagnostic message followed by the current 240input and output block counts will be written to the standard error output 241in the same format as the standard completion message. 242If the 243.Cm sync 244conversion is also specified, any missing input data will be replaced 245with 246.Dv NUL 247bytes (or with spaces if a block oriented conversion value was 248specified) and processed as a normal input buffer. 249If the 250.Cm sync 251conversion is not specified, the input block is omitted from the output. 252On input files which are not tapes or pipes, the file offset 253will be positioned past the block in which the error occurred using 254.Xr lseek 2 . 255.It Cm notrunc 256Do not truncate the output file. 257This will preserve any blocks in the output file not explicitly written 258by 259.Nm . 260The 261.Cm notrunc 262value is not supported for tapes. 263.It Cm osync 264Pad the final output block to the full output block size. 265If the input file is not a multiple of the output block size 266after conversion, this conversion forces the final output block 267to be the same size as preceding blocks for use on devices that require 268regularly sized blocks to be written. 269This option is incompatible with use of the 270.Cm bs Ns = Ns Ar n 271block size specification. 272.It Cm sparse 273If one or more output blocks would consist solely of 274.Dv NUL 275bytes, try to seek the output file by the required space instead of 276filling them with 277.Dv NUL Ns s , 278resulting in a sparse file. 279.It Cm swab 280Swap every pair of input bytes. 281If an input buffer has an odd number of bytes, the last byte will be 282ignored during swapping. 283.It Cm sync 284Pad every input block to the input buffer size. 285Spaces are used for pad bytes if a block oriented conversion value is 286specified, otherwise 287.Dv NUL 288bytes are used. 289.It Cm ucase 290Transform lowercase characters into uppercase characters. 291.It Cm unblock 292Treats the input as a sequence of fixed length records independent of input 293and output block boundaries. 294The length of the input records is specified by the 295.Cm cbs 296operand. 297Any trailing space characters are discarded and a newline character is 298appended. 299.El 300.El 301.Pp 302Where sizes are specified, a decimal, octal, or hexadecimal number of 303bytes is expected. 304If the number ends with a 305.Dq Li b , 306.Dq Li k , 307.Dq Li m , 308.Dq Li g , 309or 310.Dq Li w , 311the 312number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G) 313or the number of bytes in an integer, respectively. 314Two or more numbers may be separated by an 315.Dq Li x 316to indicate a product. 317.Pp 318When finished, 319.Nm 320displays the number of complete and partial input and output blocks, 321truncated input records and odd-length byte-swapping blocks to the 322standard error output. 323A partial input block is one where less than the input block size 324was read. 325A partial output block is one where less than the output block size 326was written. 327Partial output blocks to tape devices are considered fatal errors. 328Otherwise, the rest of the block will be written. 329Partial output blocks to character devices will produce a warning message. 330A truncated input block is one where a variable length record oriented 331conversion value was specified and the input line was too long to 332fit in the conversion record or was not newline terminated. 333.Pp 334Normally, data resulting from input or conversion or both are aggregated 335into output blocks of the specified size. 336After the end of input is reached, any remaining output is written as 337a block. 338This means that the final output block may be shorter than the output 339block size. 340.Pp 341If 342.Nm 343receives a 344.Dv SIGINFO 345(see the 346.Cm status 347argument for 348.Xr stty 1 ) 349signal, the current input and output block counts will 350be written to the standard error output 351in the same format as the standard completion message. 352If 353.Nm 354receives a 355.Dv SIGINT 356signal, the current input and output block counts will 357be written to the standard error output 358in the same format as the standard completion message and 359.Nm 360will exit. 361.Sh EXAMPLES 362Check that a disk drive contains no bad blocks: 363.Pp 364.Dl "dd if=/dev/ad0 of=/dev/null bs=1m" 365.Pp 366Do a refresh of a disk drive, in order to prevent presently 367recoverable read errors from progressing into unrecoverable read errors: 368.Pp 369.Dl "dd if=/dev/ad0 of=/dev/ad0 bs=1m" 370.Pp 371Remove parity bit from a file: 372.Pp 373.Dl "dd if=file conv=parnone of=file.txt" 374.Pp 375Check for (even) parity errors on a file: 376.Pp 377.Dl "dd if=file conv=pareven | cmp -x - file" 378.Sh DIAGNOSTICS 379.Ex -std 380.Sh SEE ALSO 381.Xr cp 1 , 382.Xr mt 1 , 383.Xr tr 1 384.Sh STANDARDS 385The 386.Nm 387utility is expected to be a superset of the 388.St -p1003.2 389standard. 390The 391.Cm files 392operand and the 393.Cm ascii , 394.Cm ebcdic , 395.Cm ibm , 396.Cm oldascii , 397.Cm oldebcdic 398and 399.Cm oldibm 400values are extensions to the 401.Tn POSIX 402standard. 403