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