xref: /minix/bin/dd/dd.1 (revision ebfedea0)
1.\"	$NetBSD: dd.1,v 1.25 2012/06/20 17:54:16 wiz Exp $
2.\"
3.\" Copyright (c) 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Keith Muller of the University of California, San Diego.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"	@(#)dd.1	8.2 (Berkeley) 1/13/94
34.\"
35.Dd November 6, 2011
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 operand ...
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 Ar n
59Set both input and output block size, superseding the
60.Cm ibs
61and
62.Cm obs
63operands.
64If no conversion values other than
65.Cm noerror ,
66.Cm notrunc
67or
68.Cm sync
69are specified, then each input block is copied to the output as a
70single block without any aggregation of short blocks.
71.It Cm cbs= Ns Ar n
72Set the conversion record size to
73.Va n
74bytes.
75The conversion record size is required by the record oriented conversion
76values.
77.It Cm count= Ns Ar n
78Copy only
79.Va n
80input blocks.
81.It Cm files= Ns Ar n
82Copy
83.Va n
84input files before terminating.
85This operand is only applicable when the input device is a tape.
86.It Cm ibs= Ns Ar n
87Set the input block size to
88.Va n
89bytes instead of the default 512.
90.It Cm if= Ns Ar file
91Read input from
92.Ar file
93instead of the standard input.
94.It Cm iseek= Ns Ar n
95Seek on the input file
96.Ar n
97blocks.
98This is synonymous with
99.Cm skip= Ns Ar n .
100.It Cm msgfmt= Ns Ar fmt
101Specify the message format
102.Ar fmt
103to be used when writing information to standard output.
104Possible values are:
105.Bl -tag -width xxxxx -offset indent -compact
106.It quiet
107turns off information summary report except for errors and
108.Cm progress .
109.It posix
110default information summary report as specified by POSIX.
111.It human
112default information summary report extended with human-readable
113values.
114.El
115.Pp
116When
117.Ar fmt
118does not correspond to any value given above,
119it contains a string that will be used as format specifier
120for the information summary output.
121Each conversion specification is introduced by the character
122.Cm % .
123The following ones are available:
124.Bl -tag -width xx -offset indent -compact
125.It b
126total number of bytes transferred
127.It B
128total number of bytes transferred in
129.Xr humanize_number 3
130format
131.It e
132speed transfer
133.It E
134speed transfer in
135.Xr humanize_number 3
136format
137.It i
138number of partial input block(s)
139.It I
140number of full input block(s)
141.It o
142number of partial output block(s)
143.It O
144number of full output block(s)
145.It s
146time elapsed since the beginning in
147.Do seconds.ms Dc
148format
149.It p
150number of sparse output blocks
151.It t
152number of truncated blocks
153.It w
154number of odd-length swab blocks
155.It P
156singular/plural of
157.Do block Dc
158depending on number of sparse blocks
159.It T
160singular/plural of
161.Do block Dc
162depending on number of truncated blocks
163.It W
164singular/plural of
165.Do block Dc
166depending on number of swab blocks
167.El
168.It Cm obs= Ns Ar n
169Set the output block size to
170.Va n
171bytes instead of the default 512.
172.It Cm of= Ns Ar file
173Write output to
174.Ar file
175instead of the standard output.
176Any regular output file is truncated unless the
177.Cm notrunc
178conversion value is specified.
179If an initial portion of the output file is skipped (see the
180.Cm seek
181operand)
182the output file is truncated at that point.
183.It Cm oseek= Ns Ar n
184Seek on the output file
185.Ar n
186blocks.
187This is synonymous with
188.Cm seek= Ns Ar n .
189.It Cm seek= Ns Ar n
190Seek
191.Va n
192blocks from the beginning of the output before copying.
193On non-tape devices, an
194.Xr lseek 2
195operation is used.
196Otherwise, existing blocks are read and the data discarded.
197If the user does not have read permission for the tape, it is positioned
198using the tape
199.Xr ioctl 2
200function calls.
201If the seek operation is past the end of file, space from the current
202end of file to the specified offset is filled with blocks of
203.Tn NUL
204bytes.
205.It Cm skip= Ns Ar n
206Skip
207.Va n
208blocks from the beginning of the input before copying.
209On input which supports seeks, an
210.Xr lseek 2
211operation is used.
212Otherwise, input data is read and discarded.
213For pipes, the correct number of bytes is read.
214For all other devices, the correct number of blocks is read without
215distinguishing between a partial or complete block being read.
216.It Cm progress= Ns Ar n
217Switch on display of progress if
218.Va n
219is set to any non-zero value.
220This will cause a
221.Dq \&.
222to be printed (to the standard error output) for every
223.Va n
224full or partial blocks written to the output file.
225.Sm off
226.It Cm conv= Cm value Op \&, Cm value \&...
227.Sm on
228Where
229.Cm value
230is one of the symbols from the following list.
231.Bl -tag -width unblock
232.It Cm ascii , oldascii
233The same as the
234.Cm unblock
235value except that characters are translated from
236.Tn EBCDIC
237to
238.Tn ASCII
239before the
240records are converted.
241(These values imply
242.Cm unblock
243if the operand
244.Cm cbs
245is also specified.)
246There are two conversion maps for
247.Tn ASCII .
248The value
249.Cm ascii
250specifies the recommended one which is compatible with
251.At V .
252The value
253.Cm oldascii
254specifies the one used in historic
255.Tn AT\*[Am]T
256and pre-
257.Bx 4.3 Reno
258systems.
259.It Cm block
260Treats the input as a sequence of newline or end-of-file terminated variable
261length records independent of input and output block boundaries.
262Any trailing newline character is discarded.
263Each input record is converted to a fixed length output record where the
264length is specified by the
265.Cm cbs
266operand.
267Input records shorter than the conversion record size are padded with spaces.
268Input records longer than the conversion record size are truncated.
269The number of truncated input records, if any, are reported to the standard
270error output at the completion of the copy.
271.It Cm ebcdic , ibm , oldebcdic , oldibm
272The same as the
273.Cm block
274value except that characters are translated from
275.Tn ASCII
276to
277.Tn EBCDIC
278after the
279records are converted.
280(These values imply
281.Cm block
282if the operand
283.Cm cbs
284is also specified.)
285There are four conversion maps for
286.Tn EBCDIC .
287The value
288.Cm ebcdic
289specifies the recommended one which is compatible with
290.At V .
291The value
292.Cm ibm
293is a slightly different mapping, which is compatible with the
294.At V
295.Cm ibm
296value.
297The values
298.Cm oldebcdic
299and
300.Cm oldibm
301are maps used in historic
302.Tn AT\*[Am]T
303and pre
304.Bx 4.3 Reno
305systems.
306.It Cm lcase
307Transform uppercase characters into lowercase characters.
308.It Cm noerror
309Do not stop processing on an input error.
310When an input error occurs, a diagnostic message followed by the current
311input and output block counts will be written to the standard error output
312in the same format as the standard completion message.
313If the
314.Cm sync
315conversion is also specified, any missing input data will be replaced
316with
317.Tn NUL
318bytes (or with spaces if a block oriented conversion value was
319specified) and processed as a normal input buffer.
320If the
321.Cm sync
322conversion is not specified, the input block is omitted from the output.
323On input files which are not tapes or pipes, the file offset
324will be positioned past the block in which the error occurred using
325.Xr lseek 2 .
326.It Cm notrunc
327Do not truncate the output file.
328This will preserve any blocks in the output file not explicitly written
329by
330.Nm .
331The
332.Cm notrunc
333value is not supported for tapes.
334.It Cm osync
335Pad the final output block to the full output block size.
336If the input file is not a multiple of the output block size
337after conversion, this conversion forces the final output block
338to be the same size as preceding blocks for use on devices that require
339regularly sized blocks to be written.
340This option is incompatible with use of the
341.Cm bs= Ns Ar n
342block size specification.
343.It Cm sparse
344If one or more non-final output blocks would consist solely of
345.Dv NUL
346bytes, try to seek the output file by the required space instead of
347filling them with
348.Dv NUL Ns s .
349This results in a sparse file on some file systems.
350.It Cm swab
351Swap every pair of input bytes.
352If an input buffer has an odd number of bytes, the last byte will be
353ignored during swapping.
354.It Cm sync
355Pad every input block to the input buffer size.
356Spaces are used for pad bytes if a block oriented conversion value is
357specified, otherwise
358.Tn NUL
359bytes are used.
360.It Cm ucase
361Transform lowercase characters into uppercase characters.
362.It Cm unblock
363Treats the input as a sequence of fixed length records independent of input
364and output block boundaries.
365The length of the input records is specified by the
366.Cm cbs
367operand.
368Any trailing space characters are discarded and a newline character is
369appended.
370.El
371.El
372.Pp
373Where sizes are specified, a decimal number of bytes is expected.
374Two or more numbers may be separated by an
375.Dq x
376to indicate a product.
377Each number may have one of the following optional suffixes:
378.Bl -tag -width 3n -offset indent -compact
379.It b
380Block; multiply by 512
381.It k
382Kibi; multiply by 1024 (1 KiB)
383.It m
384Mebi; multiply by 1048576 (1 MiB)
385.It g
386Gibi; multiply by 1073741824 (1 GiB)
387.It t
388Tebi; multiply by 1099511627776 (1 TiB)
389.It w
390Word; multiply by the number of bytes in an integer
391.El
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
420signal
421(see the
422.Ic status
423argument for
424.Xr stty 1 ) ,
425the current input and output block counts will
426be written to the standard error output
427in the same format as the standard completion message.
428If
429.Nm
430receives a
431.Dv SIGINT
432signal, the current input and output block counts will
433be written to the standard error output
434in the same format as the standard completion message and
435.Nm
436will exit.
437.Sh EXIT STATUS
438The
439.Nm
440utility exits 0 on success and \*[Gt]0 if an error occurred.
441.Sh EXAMPLES
442To print summary information in human-readable form:
443.Pp
444.Dl dd if=/dev/zero of=/dev/null count=1 msgfmt=human
445.Pp
446To customize the information summary output and print it through
447.Xr unvis 3 :
448.Pp
449.Bd -literal -offset indent
450dd if=/dev/zero of=/dev/null count=1 \e
451     msgfmt='speed:%E, in %s seconds\en' 2\*[Gt]\*[Am]1 | unvis
452.Ed
453.Sh SEE ALSO
454.Xr cp 1 ,
455.Xr mt 1 ,
456.Xr tr 1
457.Sh STANDARDS
458The
459.Nm
460utility is expected to be a superset of the
461.St -p1003.2
462standard.
463The
464.Cm files
465and
466.Cm msgfmt
467operands and the
468.Cm ascii ,
469.Cm ebcdic ,
470.Cm ibm ,
471.Cm oldascii ,
472.Cm oldebcdic
473and
474.Cm oldibm
475values are extensions to the
476.Tn POSIX
477standard.
478