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