xref: /netbsd-src/bin/dd/dd.1 (revision cda4f8f6ee55684e8d311b86c99ea59191e6b74f)
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Keith Muller of the University of California, San Diego.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)dd.1	6.7 (Berkeley) 8/7/91
36.\"
37.Dd August 7, 1991
38.Dt DD 1
39.Os
40.Sh NAME
41.Nm dd
42.Nd Convert and copy a file.
43.Sh SYNOPSIS
44.Nm dd
45.Op operands ...
46.Sh DESCRIPTION
47The
48.Nm
49utility copies the standard input to the standard output.
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 dd
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 bs= Ns Ar n
61Set both input and output block size, 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 Ar n
74Set the conversion record size to
75.Va n
76bytes.
77The conversion record size is required by the record oriented conversion
78values.
79.It Cm count= Ns Ar n
80Copy only
81.Va n
82input blocks.
83.It Cm files= Ns Ar n
84Copy
85.Va n
86input files before terminating.
87This operand is only applicable when the input device is a tape.
88.It Cm ibs= Ns Ar n
89Set the input block size to
90.Va n
91bytes instead of the default 512.
92.It Cm if= Ns Ar file
93Read input from
94.Ar file
95instead of the standard input.
96.It Cm obs= Ns Ar n
97Set the output block size to
98.Va n
99bytes instead of the default 512.
100.It Cm of= Ns Ar file
101Write output to
102.Ar file
103instead of the standard output.
104Any regular output file is truncated unless the
105.Cm notrunc
106conversion value is specified.
107If an initial portion of the output file is skipped (see the
108.Cm seek
109operand)
110the output file is truncated at that point.
111.It Cm seek= Ns Ar n
112Seek
113.Va n
114blocks from the beginning of the output before copying.
115On non-tape devices, a
116.Xr lseek 2
117operation is used.
118Otherwise, existing blocks are read and the data discarded.
119If the user does not have read permission for the tape, it is positioned
120using the tape
121.Xr ioctl 2
122function calls.
123If the seek operation is past the end of file, space from the current
124end of file to the specified offset is filled with blocks of
125.Tn NUL
126bytes.
127.It Cm skip= Ns Ar n
128Skip
129.Va n
130blocks from the beginning of the input before copying.
131On input which supports seeks, a
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.Cm conv=
140.Ns Cm value Ns Op \&, Cm value \&...
141.Xc
142Where
143.Cm value
144is one of the symbols from the following list.
145.Bl -tag -width unblock
146.It Cm ascii , oldascii
147The same as the
148.Cm unblock
149value except that characters are translated from
150.Tn ECBDIC
151to
152.Tn ASCII
153before the
154records are converted.
155(These values imply
156.Cm unblock
157if the operand
158.Cm cbs
159is also specified.)
160There are two conversion maps for
161.Tn ASCII .
162The value
163.Cm ascii
164specifies the recommended one which is compatible with System V.
165The value
166.Cm oldascii
167specifies the one used in historic
168.Tn AT&T
169and
170.Pf pre- Bx 4.3 reno
171systems.
172.It Cm block
173Treats the input as a sequence of newline or end-of-file terminated variable
174length records independent of input and output block boundaries.
175Any trailing newline character is discarded.
176Each input record is converted to a fixed length output record where the
177length is specified by the
178.Cm cbs
179operand.
180Input records shorter than the conversion record size are padded with spaces.
181Input records longer than the conversion record size are truncated.
182The number of truncated input records, if any, are reported to the standard
183error at the completion of the copy.
184.It Cm ebcdic , ibm , oldebcdic , oldibm
185The same as the
186.Cm block
187value except that characters are translated from
188.Tn ASCII
189to
190.Tn EBCDIC
191after the
192records are converted.
193(These values imply
194.Cm block
195if the operand
196.Cm cbs
197is also specified.)
198There are four conversion maps for
199.Tn EBCDIC .
200The value
201.Cm ebcdic
202specifies the recommended one which is compatible with
203.At V .
204The value
205.Cm ibm
206is a slightly different mapping, which is compatible with the
207.At V
208.Cm ibm
209value.
210The values
211.Cm oldebcdic
212and
213.Cm oldibm
214are maps used in historic
215.Tn AT&T
216and
217.Pf pre- Bx 4.3 reno
218systems.
219.It Cm lcase
220Transform uppercase characters into lowercase characters.
221.It Cm noerror
222Do not stop processing on an input error.
223When an input error occurs, a diagnostic message followed by the current
224input and output block counts will be written to standard error in the
225same format as the standard completion message.
226If the
227.Cm sync
228conversion is also specified, any missing input data will be replaced
229with
230.Tn NUL
231bytes (or with spaces if a block oriented conversion value was
232specified) and processed as a normal input buffer.
233If the
234.Cm sync
235conversion is not specified, the input block is omitted from the output.
236On input files which are not tapes or pipes, the file offset
237will be positioned past the block in which the error occurred using
238.Xr lseek 2 .
239.It Cm notrunc
240Do not truncate the output file.
241This will preserve any blocks in the output file not explicitly written
242by
243.Nm dd .
244The
245.Cm notrunc
246value is not supported for tapes.
247.It Cm swab
248Swap every pair of input bytes.
249If an input buffer has an odd number of bytes, the last byte will be
250ignored during swapping.
251.It Cm sync
252Pad every input block to the input buffer size.
253Spaces are used for pad bytes if a block oriented conversion value is
254specified, otherwise
255.Tn NUL
256bytes are used.
257.It Cm ucase
258Transform lowercase characters into uppercase characters.
259.It Cm unblock
260Treats the input as a sequence of fixed length records independent of input
261and output block boundaries.
262The length of the input records is specified by the
263.Cm cbs
264operand.
265Any trailing space characters are discarded and a newline character is
266appended.
267.El
268.El
269.Pp
270Where sizes are specified, a decimal number of bytes is expected.
271If the number ends with a ``b'', ``k'', ``m'' or ``w'', the number
272is multiplied by 512, 1024 (1K), 1048576 (1M) or the number of bytes
273in an integer, respectively.
274Two or more numbers may be separated by an ``x'' to indicate a product.
275.Pp
276When finished,
277.Nm dd
278displays the number of complete and partial input and output blocks,
279truncated input records and odd-length byte-swapping blocks to the
280standard error output.
281A partial input block is one where less than the input block size
282was read.
283A partial output block is one where less than the output block size
284was written.
285Partial output blocks to tape devices are considered fatal errors.
286Otherwise, the rest of the block will be written.
287Partial output blocks to character devices will produce a warning message.
288A truncated input block is one where a variable length record oriented
289conversion value was specified and the input line was too long to
290fit in the conversion record or was not newline terminated.
291.Pp
292Normally, data resulting from input or conversion or both are aggregated
293into output blocks of the specified size.
294After the end of input is reached, any remaining output is written as
295a block.
296This means that the final output block may be shorter than the output
297block size.
298.Pp
299If
300.Nm dd
301receives a
302.Dv SIGINFO
303(see the ``status'' argument for
304.Xr stty 1 )
305signal, the current input and output block counts will
306be written to standard error in the same format as the standard completion
307message.
308If
309.Nm dd
310receives a
311.Dv SIGINT
312signal, the current input and output block counts will
313be written to standard error in the same format as the standard completion
314message and
315.Nm dd
316will exit.
317.Pp
318The
319.Nm dd
320utility exits 0 on success and >0 if an error occurred.
321.Sh SEE ALSO
322.Xr cp 1 ,
323.Xr mt 1 ,
324.Xr tr 1
325.Sh STANDARDS
326The
327.Nm dd
328utility is expected to be a superset of the
329.St -p1003.2
330standard.
331The
332.Cm files
333operand and the
334.Cm ascii ,
335.Cm ebcdic ,
336.Cm ibm ,
337.Cm oldascii ,
338.Cm oldebcdic
339and
340.Cm oldibm
341values are extensions to the
342.Tn POSIX
343standard.
344