1.\"- 2.\" Copyright (c) 1990, 1993 3.\" The Regents of the University of California. All rights reserved. 4.\" 5.\" This code is derived from software contributed to Berkeley by 6.\" Keith Muller of the University of California, San Diego. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)dd.1 8.2 (Berkeley) 1/13/94 33.\" 34.Dd June 4, 2020 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 "of=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 fillchar Ns = Ns Ar c 88When padding a block in conversion mode or due to use of 89.Cm noerror 90and 91.Cm sync 92modes, fill with the specified 93.Tn ASCII 94character, rather than using a space or 95.Dv NUL . 96.It Cm ibs Ns = Ns Ar n 97Set the input block size to 98.Ar n 99bytes instead of the default 512. 100.It Cm if Ns = Ns Ar file 101Read input from 102.Ar file 103instead of the standard input. 104.It Cm iflag Ns = Ns Ar value Ns Op , Ns Ar value ... 105Where 106.Cm value 107is one of the symbols from the following list. 108.Bl -tag -width "fullblock" 109.It Cm fullblock 110Reading from the input file may not obtain a full block. 111When a read returns short, continue reading to fill the block. 112Without this flag, 113.Cm count 114limits the number of times 115.Xr read 2 116is called on the input rather than the number of blocks copied in full. 117May not be combined with 118.Cm conv=sync . 119.It Cm direct 120Set the O_DIRECT flag on the input file to make reads bypass any local caching. 121.El 122.It Cm iseek Ns = Ns Ar n 123Seek on the input file 124.Ar n 125blocks. 126This is synonymous with 127.Cm skip Ns = Ns Ar n . 128.It Cm obs Ns = Ns Ar n 129Set the output block size to 130.Ar n 131bytes instead of the default 512. 132.It Cm of Ns = Ns Ar file 133Write output to 134.Ar file 135instead of the standard output. 136Any regular output file is truncated unless the 137.Cm notrunc 138conversion value is specified. 139If an initial portion of the output file is seeked past (see the 140.Cm oseek 141operand), 142the output file is truncated at that point. 143.It Cm oflag Ns = Ns Ar value Ns Op , Ns Ar value ... 144Where 145.Cm value 146is one of the symbols from the following list. 147.Bl -tag -width "direct" 148.It Cm fsync 149Set the O_FSYNC flag on the output file to make writes synchronous. 150.It Cm sync 151Set the O_SYNC flag on the output file to make writes synchronous. 152This is synonymous with the 153.Cm fsync 154value. 155.It Cm direct 156Set the O_DIRECT flag on the output file to make writes bypass any local caching. 157.El 158.It Cm oseek Ns = Ns Ar n 159Seek on the output file 160.Ar n 161blocks. 162This is synonymous with 163.Cm seek Ns = Ns Ar n . 164.It Cm seek Ns = Ns Ar n 165Seek 166.Ar n 167blocks from the beginning of the output before copying. 168On non-tape devices, an 169.Xr lseek 2 170operation is used. 171Otherwise, existing blocks are read and the data discarded. 172If the user does not have read permission for the tape, it is positioned 173using the tape 174.Xr ioctl 2 175function calls. 176If the seek operation is past the end of file, space from the current 177end of file to the specified offset is filled with blocks of 178.Dv NUL 179bytes. 180.It Cm skip Ns = Ns Ar n 181Skip 182.Ar n 183blocks from the beginning of the input before copying. 184On input which supports seeks, an 185.Xr lseek 2 186operation is used. 187Otherwise, input data is read and discarded. 188For pipes, the correct number of bytes is read. 189For all other devices, the correct number of blocks is read without 190distinguishing between a partial or complete block being read. 191.It Cm speed Ns = Ns Ar n 192Limit the copying speed to 193.Ar n 194bytes per second. 195.It Cm status Ns = Ns Ar value 196Where 197.Cm value 198is one of the symbols from the following list. 199.Bl -tag -width "progress" 200.It Cm noxfer 201Do not print the transfer statistics as the last line of status output. 202.It Cm none 203Do not print the status output. 204Error messages are shown; informational messages are not. 205.It Cm progress 206Print basic transfer statistics once per second. 207.El 208.It Cm conv Ns = Ns Ar value Ns Op , Ns Ar value ... 209Where 210.Cm value 211is one of the symbols from the following list. 212.Bl -tag -width "unblock" 213.It Cm ascii , oldascii 214The same as the 215.Cm unblock 216value except that characters are translated from 217.Tn EBCDIC 218to 219.Tn ASCII 220before the 221records are converted. 222(These values imply 223.Cm unblock 224if the operand 225.Cm cbs 226is also specified.) 227There are two conversion maps for 228.Tn ASCII . 229The value 230.Cm ascii 231specifies the recommended one which is compatible with 232.At V . 233The value 234.Cm oldascii 235specifies the one used in historic 236.At 237and 238.No pre- Ns Bx 4.3 reno 239systems. 240.It Cm block 241Treats the input as a sequence of newline or end-of-file terminated variable 242length records independent of input and output block boundaries. 243Any trailing newline character is discarded. 244Each input record is converted to a fixed length output record where the 245length is specified by the 246.Cm cbs 247operand. 248Input records shorter than the conversion record size are padded with spaces. 249Input records longer than the conversion record size are truncated. 250The number of truncated input records, if any, are reported to the standard 251error output at the completion of the copy. 252.It Cm ebcdic , ibm , oldebcdic , oldibm 253The same as the 254.Cm block 255value except that characters are translated from 256.Tn ASCII 257to 258.Tn EBCDIC 259after the 260records are converted. 261(These values imply 262.Cm block 263if the operand 264.Cm cbs 265is also specified.) 266There are four conversion maps for 267.Tn EBCDIC . 268The value 269.Cm ebcdic 270specifies the recommended one which is compatible with 271.At V . 272The value 273.Cm ibm 274is a slightly different mapping, which is compatible with the 275.At V 276.Cm ibm 277value. 278The values 279.Cm oldebcdic 280and 281.Cm oldibm 282are maps used in historic 283.At 284and 285.No pre- Ns Bx 4.3 reno 286systems. 287.It Cm fdatasync 288Perform an 289.Xr fdatasync 2 290on the output file before closing it. 291.It Cm fsync 292Perform an 293.Xr fsync 2 294on the output file before closing it. 295.It Cm lcase 296Transform uppercase characters into lowercase characters. 297.It Cm pareven , parnone , parodd , parset 298Output data with the specified parity. 299The parity bit on input is stripped unless 300.Tn EBCDIC 301to 302.Tn ASCII 303conversions is also specified. 304.It Cm noerror 305Do not stop processing on an input error. 306When an input error occurs, a diagnostic message followed by the current 307input and output block counts will be written to the standard error output 308in the same format as the standard completion message. 309If the 310.Cm sync 311conversion is also specified, any missing input data will be replaced 312with 313.Dv NUL 314bytes (or with spaces if a block oriented conversion value was 315specified) and processed as a normal input buffer. 316If the 317.Cm fillchar 318option is specified, the fill character provided on the command line 319will override 320the automatic selection of the fill character. 321If the 322.Cm sync 323conversion is not specified, the input block is omitted from the output. 324On input files which are not tapes or pipes, the file offset 325will be positioned past the block in which the error occurred using 326.Xr lseek 2 . 327.It Cm notrunc 328Do not truncate the output file. 329This will preserve any blocks in the output file not explicitly written 330by 331.Nm . 332The 333.Cm notrunc 334value is not supported for tapes. 335.It Cm osync 336Pad the final output block to the full output block size. 337If the input file is not a multiple of the output block size 338after conversion, this conversion forces the final output block 339to be the same size as preceding blocks for use on devices that require 340regularly sized blocks to be written. 341This option is incompatible with use of the 342.Cm bs Ns = Ns Ar n 343block size specification. 344.It Cm sparse 345If one or more output blocks would consist solely of 346.Dv NUL 347bytes, try to seek the output file by the required space instead of 348filling them with 349.Dv NUL Ns s , 350resulting in a sparse file. 351.It Cm swab 352Swap every pair of input bytes. 353If an input buffer has an odd number of bytes, the last byte will be 354ignored during swapping. 355.It Cm sync 356Pad every input block to the input buffer size. 357Spaces are used for pad bytes if a block oriented conversion value is 358specified, otherwise 359.Dv NUL 360bytes are used. 361.It Cm ucase 362Transform lowercase characters into uppercase characters. 363.It Cm unblock 364Treats the input as a sequence of fixed length records independent of input 365and output block boundaries. 366The length of the input records is specified by the 367.Cm cbs 368operand. 369Any trailing space characters are discarded and a newline character is 370appended. 371.El 372.El 373.Pp 374Where sizes or speed are specified, a decimal, octal, or hexadecimal number of 375bytes is expected. 376If the number ends with a 377.Dq Li b , 378.Dq Li k , 379.Dq Li m , 380.Dq Li g , 381.Dq Li t , 382.Dq Li p , 383or 384.Dq Li w , 385the 386number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G), 3871099511627776 (1T), 1125899906842624 (1P) 388or the number of bytes in an integer, respectively. 389Two or more numbers may be separated by an 390.Dq Li x 391to indicate a product. 392.Pp 393When finished, 394.Nm 395displays the number of complete and partial input and output blocks, 396truncated input records and odd-length byte-swapping blocks to the 397standard error output. 398A partial input block is one where less than the input block size 399was read. 400A partial output block is one where less than the output block size 401was written. 402Partial output blocks to tape devices are considered fatal errors. 403Otherwise, the rest of the block will be written. 404Partial output blocks to character devices will produce a warning message. 405A truncated input block is one where a variable length record oriented 406conversion value was specified and the input line was too long to 407fit in the conversion record or was not newline terminated. 408.Pp 409Normally, data resulting from input or conversion or both are aggregated 410into output blocks of the specified size. 411After the end of input is reached, any remaining output is written as 412a block. 413This means that the final output block may be shorter than the output 414block size. 415.Pp 416If 417.Nm 418receives a 419.Dv SIGINFO 420(see the 421.Cm status 422argument for 423.Xr stty 1 ) 424signal, the current input and output block counts will 425be written to the standard error output 426in the same format as the standard completion message. 427If 428.Nm 429receives a 430.Dv SIGINT 431signal, the current input and output block counts will 432be written to the standard error output 433in the same format as the standard completion message and 434.Nm 435will exit. 436.Sh EXIT STATUS 437.Ex -std 438.Sh EXAMPLES 439Check that a disk drive contains no bad blocks: 440.Pp 441.Dl "dd if=/dev/ada0 of=/dev/null bs=1m" 442.Pp 443Do a refresh of a disk drive, in order to prevent presently 444recoverable read errors from progressing into unrecoverable read errors: 445.Pp 446.Dl "dd if=/dev/ada0 of=/dev/ada0 bs=1m" 447.Pp 448Remove parity bit from a file: 449.Pp 450.Dl "dd if=file conv=parnone of=file.txt" 451.Pp 452Check for (even) parity errors on a file: 453.Pp 454.Dl "dd if=file conv=pareven | cmp -x - file" 455.Pp 456To create an image of a Mode-1 CD-ROM, which is a commonly used format 457for data CD-ROM disks, use a block size of 2048 bytes: 458.Pp 459.Dl "dd if=/dev/cd0 of=filename.iso bs=2048" 460.Pp 461Write a filesystem image to a memory stick, padding the end with zeros, 462if necessary, to a 1MiB boundary: 463.Pp 464.Dl "dd if=memstick.img of=/dev/da0 bs=1m conv=noerror,sync" 465.Sh SEE ALSO 466.Xr cp 1 , 467.Xr mt 1 , 468.Xr recoverdisk 1 , 469.Xr tr 1 , 470.Xr geom 4 , 471.Xr trim 8 472.Sh STANDARDS 473The 474.Nm 475utility is expected to be a superset of the 476.St -p1003.2 477standard. 478The 479.Cm files 480and 481.Cm status 482operands and the 483.Cm ascii , 484.Cm ebcdic , 485.Cm ibm , 486.Cm oldascii , 487.Cm oldebcdic 488and 489.Cm oldibm 490values are extensions to the 491.Tn POSIX 492standard. 493.Sh HISTORY 494A 495.Nm 496command appeared in 497.At v5 . 498.Sh BUGS 499Protection mechanisms in the 500.Xr geom 4 501subsystem might prevent the super-user from writing blocks to a disk. 502Instructions for temporarily disabling these protection mechanisms can be 503found in the 504.Xr geom 4 505man page. 506