xref: /openbsd/bin/dd/dd.1 (revision 998de4a5)
1.\"	$OpenBSD: dd.1,v 1.33 2016/08/17 21:23:01 schwarze Exp $
2.\"	$NetBSD: dd.1,v 1.5 1995/03/21 09:04:04 cgd Exp $
3.\"
4.\" Copyright (c) 1990, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" Keith Muller of the University of California, San Diego.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"	@(#)dd.1	8.2 (Berkeley) 1/13/94
35.\"
36.Dd $Mdocdate: August 17 2016 $
37.Dt DD 1
38.Os
39.Sh NAME
40.Nm dd
41.Nd convert and copy a file
42.Sh SYNOPSIS
43.Nm dd
44.Op Ar operand ...
45.Sh DESCRIPTION
46The
47.Nm
48utility copies the standard input to the standard output, applying any
49specified conversions.
50Input data is read and written in 512-byte blocks.
51If input reads are short, input from multiple reads are aggregated
52to form the output block.
53When finished,
54.Nm
55displays the number of complete and partial input and output blocks
56and truncated input records to the standard error output.
57.Pp
58The following operands are available:
59.Bl -tag -width of=file
60.It Cm if= Ns Ar file
61Read input from
62.Ar file
63instead of the standard input.
64.It Cm of= Ns Ar file
65Write output to
66.Ar file
67instead of the standard output.
68Any regular output file is truncated unless the
69.Cm notrunc
70conversion value is specified.
71If an initial portion of the output file is skipped (see the
72.Cm seek
73operand),
74the output file is truncated at that point.
75.It Cm ibs= Ns Ar n
76Set the input block size to
77.Ar n
78bytes instead of the default 512.
79.It Cm obs= Ns Ar n
80Set the output block size to
81.Ar n
82bytes instead of the default 512.
83.It Cm bs= Ns Ar n
84Set both the input and output block size to
85.Ar n
86bytes, superseding the
87.Cm ibs
88and
89.Cm obs
90operands.
91If no conversion values other than
92.Cm noerror ,
93.Cm notrunc ,
94or
95.Cm sync
96are specified, then each input block is copied to the output as a
97single block without any aggregation of short blocks.
98.It Cm cbs= Ns Ar n
99Set the conversion record size to
100.Ar n
101bytes.
102The conversion record size is required by the record oriented conversion
103values.
104.It Cm count= Ns Ar n
105Copy only
106.Ar n
107input blocks.
108.It Cm files= Ns Ar n
109Copy
110.Ar n
111input files before terminating.
112This operand is only applicable when the input device is a tape.
113.It Cm seek= Ns Ar n
114Seek
115.Ar n
116blocks from the beginning of the output before copying.
117On non-tape devices, an
118.Xr lseek 2
119operation is used.
120Otherwise, existing blocks are read and the data discarded.
121If the user does not have read permission for the tape, it is positioned
122using the tape
123.Xr ioctl 2
124function calls.
125If the seek operation is past the end of file, space from the current
126end of file to the specified offset is filled with blocks of NUL bytes.
127.It Cm skip= Ns Ar n
128Skip
129.Ar n
130blocks from the beginning of the input before copying.
131On input which supports seeks, an
132.Xr lseek 2
133operation is used.
134Otherwise, input data is read and discarded.
135For pipes, the correct number of bytes is read.
136For all other devices, the correct number of blocks is read without
137distinguishing between a partial or complete block being read.
138.It Xo
139.Sm off
140.Cm status= Ar value
141.Sm on
142.Xc
143Where
144.Ar value
145is one of the symbols from the following list.
146.Bl -tag -width unblock
147.It Cm noxfer
148Do not print the transfer statistics as the last line of status output.
149.It Cm none
150Do not print the status output.
151Error messages are shown; informational messages are not.
152.El
153.It Xo
154.Sm off
155.Cm conv= Ar value Oo ,
156.Sm on
157.Ar value ... Oc
158.Xc
159Where
160.Ar value
161is one of the symbols from the following list.
162.Bl -tag -width unblock
163.It Cm ascii
164The same as the
165.Cm unblock
166value except that characters are translated from EBCDIC to ASCII
167before the records are converted.
168(These values imply
169.Cm unblock
170if the operand
171.Cm cbs
172is also specified.)
173.It Cm block
174Treats the input as a sequence of newline or end-of-file terminated variable
175length records independent of input and output block boundaries.
176Any trailing newline character is discarded.
177Each input record is converted to a fixed length output record where the
178length is specified by the
179.Cm cbs
180operand.
181Input records shorter than the conversion record size are padded with spaces.
182Input records longer than the conversion record size are truncated.
183The number of truncated input records, if any, is reported to the standard
184error output at the completion of the copy.
185.It Cm ebcdic , ibm
186The same as the
187.Cm block
188value except that characters are translated from ASCII to EBCDIC
189after the records are converted.
190(These values imply
191.Cm block
192if the operand
193.Cm cbs
194is also specified.)
195There are two conversion maps for EBCDIC.
196The value
197.Cm ebcdic
198specifies the recommended one which is compatible with
199.At V .
200The value
201.Cm ibm
202is a slightly different mapping, which is compatible with the
203.At V
204.Cm ibm
205value.
206.It Cm lcase
207Transform uppercase characters into lowercase characters.
208.It Cm noerror
209Do not stop processing on an input error.
210When an input error occurs, a diagnostic message followed by the current
211input and output block counts will be written to the standard error output
212in the same format as the standard completion message.
213If the
214.Cm sync
215conversion is also specified, any missing input data will be replaced
216with NUL bytes (or with spaces if a block oriented conversion value was
217specified) and processed as a normal input buffer.
218If the
219.Cm sync
220conversion is not specified, the input block is omitted from the output.
221On input files which are not tapes or pipes, the file offset
222will be positioned past the block in which the error occurred using
223.Xr lseek 2 .
224.It Cm notrunc
225Do not truncate the output file.
226This will preserve any blocks in the output file not explicitly written
227by
228.Nm dd .
229The
230.Cm notrunc
231value is not supported for tapes.
232.It Cm osync
233Pad the final output block to the full output block size.
234If the input file is not a multiple of the output block size
235after conversion, this conversion forces the final output block
236to be the same size as preceding blocks for use on devices that require
237regularly sized blocks to be written.
238This option is incompatible with use of the
239.Cm bs= Ns Ar n
240block size specification.
241.It Cm swab
242Swap every pair of input bytes.
243If an input buffer has an odd number of bytes, the last byte will be
244ignored during swapping.
245.It Cm sync
246Pad every input block to the input buffer size.
247Spaces are used for pad bytes if a block oriented conversion value is
248specified, otherwise NUL bytes are used.
249.It Cm ucase
250Transform lowercase characters into uppercase characters.
251.It Cm unblock
252Treats the input as a sequence of fixed length records independent of input
253and output block boundaries.
254The length of the input records is specified by the
255.Cm cbs
256operand.
257Any trailing space characters are discarded and a newline character is
258appended.
259.El
260.El
261.Pp
262Where sizes are specified, a decimal number of bytes is expected.
263If the number ends with a
264.Sq b ,
265.Sq k
266or
267.Sq K ,
268.Sq m
269or
270.Sq M ,
271.Sq g
272or
273.Sq G ,
274or
275.Sq w ,
276the number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G),
277or the number of bytes in an integer, respectively.
278Two or more numbers may be separated by an
279.Sq x
280to indicate a product.
281.Pp
282When finished,
283.Nm
284displays the number of complete and partial input and output blocks,
285truncated input records, and odd-length byte-swapping blocks to the
286standard error output.
287A partial input block is one where less than the input block size
288was read.
289A partial output block is one where less than the output block size
290was written.
291Partial output blocks to tape devices are considered fatal errors.
292Otherwise, the rest of the block will be written.
293Partial output blocks to character devices will produce a warning message.
294A truncated input block is one where a variable length record oriented
295conversion value was specified and the input line was too long to
296fit in the conversion record or was not newline terminated.
297.Pp
298Normally, data resulting from input or conversion or both are aggregated
299into output blocks of the specified size.
300After the end of input is reached, any remaining output is written as
301a block.
302This means that the final output block may be shorter than the output
303block size.
304.Pp
305If
306.Nm
307receives a
308.Dv SIGINFO
309(see the
310.Dq status
311argument for
312.Xr stty 1 )
313signal, the current input and output block counts will
314be written to the standard error output
315in the same format as the standard completion message.
316If
317.Nm
318receives a
319.Dv SIGINT
320signal, the current input and output block counts will
321be written to the standard error output
322in the same format as the standard completion message and
323.Nm
324will exit.
325.Sh EXIT STATUS
326.Ex -std dd
327.Sh EXAMPLES
328Write an
329.Ox
330floppy image to a floppy disk:
331.Pp
332.Dl # dd if=floppy34.fs of=/dev/rfd0c bs=32k
333.Pp
334Create an ISO-9660 image of a CD-ROM:
335.Pp
336.Dl # dd if=/dev/rcd0c of=disk.iso bs=32k
337.Sh SEE ALSO
338.Xr cp 1 ,
339.Xr mt 1 ,
340.Xr tr 1
341.Sh STANDARDS
342The
343.Nm
344utility is compliant with the
345.St -p1003.1-2008
346specification.
347.Pp
348The conversions
349.Cm ascii ,
350.Cm ebcdic ,
351and
352.Cm ibm
353are marked by
354.St -p1003.1-2008
355as being an
356X/Open System Interfaces option.
357.Pp
358The
359.Cm files
360and
361.Cm status
362operands,
363the
364.Cm osync
365conversion,
366the
367.Sq K ,
368.Sq m ,
369.Sq M ,
370.Sq g ,
371.Sq G ,
372and
373.Sq w
374size multipliers
375and
376.Dv SIGINFO
377handling
378are all extensions to the
379.St -p1003.1-2008
380specification.
381.Sh HISTORY
382A
383.Nm
384utility appeared in
385.At v5 .
386