xref: /freebsd/bin/dd/dd.1 (revision afe61c15161c324a7af299a9b8457aba5afc92db)
1.\" Copyright (c) 1990, 1993
2.\"	The Regents of the University of California.  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	8.2 (Berkeley) 1/13/94
36.\"
37.Dd January 13, 1994
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 pre-4.3BSD-reno systems.
170.It Cm block
171Treats the input as a sequence of newline or end-of-file terminated variable
172length records independent of input and output block boundaries.
173Any trailing newline character is discarded.
174Each input record is converted to a fixed length output record where the
175length is specified by the
176.Cm cbs
177operand.
178Input records shorter than the conversion record size are padded with spaces.
179Input records longer than the conversion record size are truncated.
180The number of truncated input records, if any, are reported to the standard
181error output at the completion of the copy.
182.It Cm ebcdic , ibm , oldebcdic , oldibm
183The same as the
184.Cm block
185value except that characters are translated from
186.Tn ASCII
187to
188.Tn EBCDIC
189after the
190records are converted.
191(These values imply
192.Cm block
193if the operand
194.Cm cbs
195is also specified.)
196There are four conversion maps for
197.Tn EBCDIC .
198The value
199.Cm ebcdic
200specifies the recommended one which is compatible with
201.At V .
202The value
203.Cm ibm
204is a slightly different mapping, which is compatible with the
205.At V
206.Cm ibm
207value.
208The values
209.Cm oldebcdic
210and
211.Cm oldibm
212are maps used in historic
213.Tn AT&T
214and pre-4.3BSD-reno systems.
215.It Cm lcase
216Transform uppercase characters into lowercase characters.
217.It Cm noerror
218Do not stop processing on an input error.
219When an input error occurs, a diagnostic message followed by the current
220input and output block counts will be written to the standard error output
221in the same format as the standard completion message.
222If the
223.Cm sync
224conversion is also specified, any missing input data will be replaced
225with
226.Tn NUL
227bytes (or with spaces if a block oriented conversion value was
228specified) and processed as a normal input buffer.
229If the
230.Cm sync
231conversion is not specified, the input block is omitted from the output.
232On input files which are not tapes or pipes, the file offset
233will be positioned past the block in which the error occurred using
234.Xr lseek 2 .
235.It Cm notrunc
236Do not truncate the output file.
237This will preserve any blocks in the output file not explicitly written
238by
239.Nm dd .
240The
241.Cm notrunc
242value is not supported for tapes.
243.It Cm osync
244Pad the final output block to the full output block size.
245If the input file is not a multiple of the output block size
246after conversion, this conversion forces the final output block
247to be the same size as preceding blocks for use on devices that require
248regularly sized blocks to be written.
249This option is incompatible with use of the
250.Cm bs= Ns Ar n
251block size specification.
252.It Cm swab
253Swap every pair of input bytes.
254If an input buffer has an odd number of bytes, the last byte will be
255ignored during swapping.
256.It Cm sync
257Pad every input block to the input buffer size.
258Spaces are used for pad bytes if a block oriented conversion value is
259specified, otherwise
260.Tn NUL
261bytes are used.
262.It Cm ucase
263Transform lowercase characters into uppercase characters.
264.It Cm unblock
265Treats the input as a sequence of fixed length records independent of input
266and output block boundaries.
267The length of the input records is specified by the
268.Cm cbs
269operand.
270Any trailing space characters are discarded and a newline character is
271appended.
272.El
273.El
274.Pp
275Where sizes are specified, a decimal number of bytes is expected.
276If the number ends with a ``b'', ``k'', ``m'' or ``w'', the number
277is multiplied by 512, 1024 (1K), 1048576 (1M) or the number of bytes
278in an integer, respectively.
279Two or more numbers may be separated by an ``x'' to indicate a product.
280.Pp
281When finished,
282.Nm dd
283displays the number of complete and partial input and output blocks,
284truncated input records and odd-length byte-swapping blocks to the
285standard error output.
286A partial input block is one where less than the input block size
287was read.
288A partial output block is one where less than the output block size
289was written.
290Partial output blocks to tape devices are considered fatal errors.
291Otherwise, the rest of the block will be written.
292Partial output blocks to character devices will produce a warning message.
293A truncated input block is one where a variable length record oriented
294conversion value was specified and the input line was too long to
295fit in the conversion record or was not newline terminated.
296.Pp
297Normally, data resulting from input or conversion or both are aggregated
298into output blocks of the specified size.
299After the end of input is reached, any remaining output is written as
300a block.
301This means that the final output block may be shorter than the output
302block size.
303.Pp
304If
305.Nm dd
306receives a
307.Dv SIGINFO
308(see the ``status'' argument for
309.Xr stty 1 )
310signal, the current input and output block counts will
311be written to the standard error output
312in the same format as the standard completion message.
313If
314.Nm dd
315receives a
316.Dv SIGINT
317signal, the current input and output block counts will
318be written to the standard error output
319in the same format as the standard completion message and
320.Nm dd
321will exit.
322.Pp
323The
324.Nm dd
325utility exits 0 on success and >0 if an error occurred.
326.Sh SEE ALSO
327.Xr cp 1 ,
328.Xr mt 1 ,
329.Xr tr 1
330.Sh STANDARDS
331The
332.Nm dd
333utility is expected to be a superset of the
334.St -p1003.2
335standard.
336The
337.Cm files
338operand and the
339.Cm ascii ,
340.Cm ebcdic ,
341.Cm ibm ,
342.Cm oldascii ,
343.Cm oldebcdic
344and
345.Cm oldibm
346values are extensions to the
347.Tn POSIX
348standard.
349