xref: /minix/bin/dd/dd.1 (revision 02efe53e)
1.\"	$NetBSD: dd.1,v 1.32 2016/08/18 22:43:49 sevan 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 August 18, 2016
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 iflag= Ns Ar flags
95Use comma-separated
96.Ar flags
97when calling
98.Xr open 2
99for the input file.
100The possible values are
101.Va O_
102flags documented in
103.Xr open 2 ,
104specified as lowercase and with the leading
105.Va O_
106removed.
107Default value is
108.Va rdonly .
109.It Cm iseek= Ns Ar n
110Seek on the input file
111.Ar n
112blocks.
113This is synonymous with
114.Cm skip= Ns Ar n .
115.It Cm msgfmt= Ns Ar fmt
116Specify the message format
117.Ar fmt
118to be used when writing information to standard output.
119Possible values are:
120.Bl -tag -width xxxxx -offset indent -compact
121.It quiet
122turns off information summary report except for errors and
123.Cm progress .
124.It posix
125default information summary report as specified by POSIX.
126.It human
127default information summary report extended with human-readable
128values.
129.El
130.Pp
131When
132.Ar fmt
133does not correspond to any value given above,
134it contains a string that will be used as format specifier
135for the information summary output.
136Each conversion specification is introduced by the character
137.Cm % .
138The following ones are available:
139.Bl -tag -width xx -offset indent -compact
140.It b
141total number of bytes transferred
142.It B
143total number of bytes transferred in
144.Xr humanize_number 3
145format
146.It e
147speed transfer
148.It E
149speed transfer in
150.Xr humanize_number 3
151format
152.It i
153number of partial input block(s)
154.It I
155number of full input block(s)
156.It o
157number of partial output block(s)
158.It O
159number of full output block(s)
160.It s
161time elapsed since the beginning in
162.Do seconds.ms Dc
163format
164.It p
165number of sparse output blocks
166.It t
167number of truncated blocks
168.It w
169number of odd-length swab blocks
170.It P
171singular/plural of
172.Do block Dc
173depending on number of sparse blocks
174.It T
175singular/plural of
176.Do block Dc
177depending on number of truncated blocks
178.It W
179singular/plural of
180.Do block Dc
181depending on number of swab blocks
182.El
183.It Cm obs= Ns Ar n
184Set the output block size to
185.Va n
186bytes instead of the default 512.
187.It Cm of= Ns Ar file
188Write output to
189.Ar file
190instead of the standard output.
191Any regular output file is truncated unless the
192.Cm notrunc
193conversion value is specified.
194If an initial portion of the output file is skipped (see the
195.Cm seek
196operand)
197the output file is truncated at that point.
198.It Cm oflag= Ns Ar flags
199Same as
200.Cm iflag
201but for the call to
202.Xr open 2
203on the output file.
204The default value is
205.Va creat ,
206which should be explicitly added in
207.Cm oflag
208in order to output to a nonexistent file.
209The default or specified value is or'ed with
210.Va rdwr
211for a first
212.Xr open 2
213attempt, then on failure with
214.Va wronly
215on a second attempt.
216In both cases,
217.Va trunc
218is automatically added if none of
219.Cm oseek ,
220.Cm seek ,
221or
222.Cm conv=notrunc
223operands are used,
224.It Cm oseek= Ns Ar n
225Seek on the output file
226.Ar n
227blocks.
228This is synonymous with
229.Cm seek= Ns Ar n .
230.It Cm seek= Ns Ar n
231Seek
232.Va n
233blocks from the beginning of the output before copying.
234On non-tape devices, an
235.Xr lseek 2
236operation is used.
237Otherwise, existing blocks are read and the data discarded.
238If the user does not have read permission for the tape, it is positioned
239using the tape
240.Xr ioctl 2
241function calls.
242If the seek operation is past the end of file, space from the current
243end of file to the specified offset is filled with blocks of
244.Tn NUL
245bytes.
246.It Cm skip= Ns Ar n
247Skip
248.Va n
249blocks from the beginning of the input before copying.
250On input which supports seeks, an
251.Xr lseek 2
252operation is used.
253Otherwise, input data is read and discarded.
254For pipes, the correct number of bytes is read.
255For all other devices, the correct number of blocks is read without
256distinguishing between a partial or complete block being read.
257.It Cm progress= Ns Ar n
258Switch on display of progress if
259.Va n
260is set to any non-zero value.
261This will cause a
262.Dq \&.
263to be printed (to the standard error output) for every
264.Va n
265full or partial blocks written to the output file.
266.Sm off
267.It Cm conv= Cm value Op \&, Cm value \&...
268.Sm on
269Where
270.Cm value
271is one of the symbols from the following list.
272.Bl -tag -width unblock
273.It Cm ascii , oldascii
274The same as the
275.Cm unblock
276value except that characters are translated from
277.Tn EBCDIC
278to
279.Tn ASCII
280before the
281records are converted.
282(These values imply
283.Cm unblock
284if the operand
285.Cm cbs
286is also specified.)
287There are two conversion maps for
288.Tn ASCII .
289The value
290.Cm ascii
291specifies the recommended one which is compatible with
292.At V .
293The value
294.Cm oldascii
295specifies the one used in historic
296.Tn AT\*[Am]T
297and pre-
298.Bx 4.3 Reno
299systems.
300.It Cm block
301Treats the input as a sequence of newline or end-of-file terminated variable
302length records independent of input and output block boundaries.
303Any trailing newline character is discarded.
304Each input record is converted to a fixed length output record where the
305length is specified by the
306.Cm cbs
307operand.
308Input records shorter than the conversion record size are padded with spaces.
309Input records longer than the conversion record size are truncated.
310The number of truncated input records, if any, are reported to the standard
311error output at the completion of the copy.
312.It Cm ebcdic , ibm , oldebcdic , oldibm
313The same as the
314.Cm block
315value except that characters are translated from
316.Tn ASCII
317to
318.Tn EBCDIC
319after the
320records are converted.
321(These values imply
322.Cm block
323if the operand
324.Cm cbs
325is also specified.)
326There are four conversion maps for
327.Tn EBCDIC .
328The value
329.Cm ebcdic
330specifies the recommended one which is compatible with
331.At V .
332The value
333.Cm ibm
334is a slightly different mapping, which is compatible with the
335.At V
336.Cm ibm
337value.
338The values
339.Cm oldebcdic
340and
341.Cm oldibm
342are maps used in historic
343.Tn AT\*[Am]T
344and pre
345.Bx 4.3 Reno
346systems.
347.It Cm lcase
348Transform uppercase characters into lowercase characters.
349.It Cm noerror
350Do not stop processing on an input error.
351When an input error occurs, a diagnostic message followed by the current
352input and output block counts will be written to the standard error output
353in the same format as the standard completion message.
354If the
355.Cm sync
356conversion is also specified, any missing input data will be replaced
357with
358.Tn NUL
359bytes (or with spaces if a block oriented conversion value was
360specified) and processed as a normal input buffer.
361If the
362.Cm sync
363conversion is not specified, the input block is omitted from the output.
364On input files which are not tapes or pipes, the file offset
365will be positioned past the block in which the error occurred using
366.Xr lseek 2 .
367.It Cm notrunc
368Do not truncate the output file.
369This will preserve any blocks in the output file not explicitly written
370by
371.Nm .
372The
373.Cm notrunc
374value is not supported for tapes.
375.It Cm osync
376Pad the final output block to the full output block size.
377If the input file is not a multiple of the output block size
378after conversion, this conversion forces the final output block
379to be the same size as preceding blocks for use on devices that require
380regularly sized blocks to be written.
381This option is incompatible with use of the
382.Cm bs= Ns Ar n
383block size specification.
384.It Cm sparse
385If one or more non-final output blocks would consist solely of
386.Dv NUL
387bytes, try to seek the output file by the required space instead of
388filling them with
389.Dv NUL Ns s .
390This results in a sparse file on some file systems.
391.It Cm swab
392Swap every pair of input bytes.
393If an input buffer has an odd number of bytes, the last byte will be
394ignored during swapping.
395.It Cm sync
396Pad every input block to the input buffer size.
397Spaces are used for pad bytes if a block oriented conversion value is
398specified, otherwise
399.Tn NUL
400bytes are used.
401.It Cm ucase
402Transform lowercase characters into uppercase characters.
403.It Cm unblock
404Treats the input as a sequence of fixed length records independent of input
405and output block boundaries.
406The length of the input records is specified by the
407.Cm cbs
408operand.
409Any trailing space characters are discarded and a newline character is
410appended.
411.El
412.El
413.Pp
414Where sizes are specified, a decimal number of bytes is expected.
415Two or more numbers may be separated by an
416.Dq x
417to indicate a product.
418Each number may have one of the following optional suffixes:
419.Bl -tag -width 3n -offset indent -compact
420.It b
421Block; multiply by 512
422.It k
423Kibi; multiply by 1024 (1 KiB)
424.It m
425Mebi; multiply by 1048576 (1 MiB)
426.It g
427Gibi; multiply by 1073741824 (1 GiB)
428.It t
429Tebi; multiply by 1099511627776 (1 TiB)
430.It w
431Word; multiply by the number of bytes in an integer
432.El
433.Pp
434When finished,
435.Nm
436displays the number of complete and partial input and output blocks,
437truncated input records and odd-length byte-swapping blocks to the
438standard error output.
439A partial input block is one where less than the input block size
440was read.
441A partial output block is one where less than the output block size
442was written.
443Partial output blocks to tape devices are considered fatal errors.
444Otherwise, the rest of the block will be written.
445Partial output blocks to character devices will produce a warning message.
446A truncated input block is one where a variable length record oriented
447conversion value was specified and the input line was too long to
448fit in the conversion record or was not newline terminated.
449.Pp
450Normally, data resulting from input or conversion or both are aggregated
451into output blocks of the specified size.
452After the end of input is reached, any remaining output is written as
453a block.
454This means that the final output block may be shorter than the output
455block size.
456.Pp
457If
458.Nm
459receives a
460.Dv SIGINFO
461signal
462(see the
463.Ic status
464argument for
465.Xr stty 1 ) ,
466the current input and output block counts will
467be written to the standard error output
468in the same format as the standard completion message.
469If
470.Nm
471receives a
472.Dv SIGINT
473signal, the current input and output block counts will
474be written to the standard error output
475in the same format as the standard completion message and
476.Nm
477will exit.
478.Sh EXIT STATUS
479The
480.Nm
481utility exits 0 on success and \*[Gt]0 if an error occurred.
482.Sh EXAMPLES
483To print summary information in human-readable form:
484.Pp
485.Dl dd if=/dev/zero of=/dev/null count=1 msgfmt=human
486.Pp
487To customize the information summary output and print it through
488.Xr unvis 3 :
489.Bd -literal -offset indent
490dd if=/dev/zero of=/dev/null count=1 \e
491     msgfmt='speed:%E, in %s seconds\en' 2\*[Gt]\*[Am]1 | unvis
492.Ed
493.Sh SEE ALSO
494.Xr cp 1 ,
495.Xr mt 1 ,
496.Xr tr 1
497.Sh STANDARDS
498The
499.Nm
500utility is expected to be a superset of the
501.St -p1003.2
502standard.
503The
504.Cm files
505and
506.Cm msgfmt
507operands and the
508.Cm ascii ,
509.Cm ebcdic ,
510.Cm ibm ,
511.Cm oldascii ,
512.Cm oldebcdic
513and
514.Cm oldibm
515values are extensions to the
516.Tn POSIX
517standard.
518.Sh HISTORY
519A
520.Nm
521utility appeared in
522.At v5 .
523