1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
|
.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group. In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright 1989 AT&T
.\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Portions Copyright (c) 1995, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright (c) 2014, Joyent, Inc. All rights Reserved.
.\" Copyright (c) 2014 by Delphix. All rights reserved.
.\" Copyright 2021 Oxide Computer Company
.\"
.Dd October 24, 2021
.Dt DD 8
.Os
.Sh NAME
.Nm dd
.Nd convert and copy a file
.Sh SYNOPSIS
.Nm
.Op Ar operand Ns = Ns Ar value
.Ar ...
.Sh DESCRIPTION
The
.Nm
utility copies the specified input file to the specified output
with possible conversions.
The standard input and output are used by default.
The input and output block sizes may be specified to take advantage of raw
physical I/O.
Sizes are specified in bytes; a number may end with
.Sy k ,
.Sy b ,
or
.Sy w
to specify multiplication by 1024, 512, or 2, respectively.
Numbers may also be separated by
.Sy x
to indicate multiplication.
.Pp
The
.Nm
utility reads the input one block at a time, using the specified
input block size.
.Nm
then processes the block of data actually returned,
which could be smaller than the requested block size unless the input flag
.Ar fullblock
is used.
.Nm
applies any conversions that have been specified and writes the resulting data
to the output in blocks of the specified output block size.
.Pp
.Cm cbs
is used only if
.Cm ascii ,
.Cm asciib ,
.Cm unblock ,
.Cm ebcdic ,
.Cm ebcdicb ,
.Cm ibm ,
.Cm ibmb ,
or
.Cm block
conversion is specified.
In the first two cases,
.Cm cbs
characters are copied into the conversion buffer, any specified character
mapping is done, trailing blanks are trimmed, and a
.Cm NEWLINE
is added before sending the line to output.
In the last three cases, characters up to
.Cm NEWLINE
are read into the conversion buffer and blanks are added to make up an output
record of size
.Cm cbs .
.Cm ASCII
files are presumed to contain
.Cm NEWLINE
characters.
If
.Cm cbs
is unspecified or
.Cm 0 ,
the
.Cm ascii ,
.Cm asciib ,
.Cm ebcdic ,
.Cm ebcdicb ,
.Cm ibm ,
and
.Cm ibmb
options convert the character set without changing the input file's block
structure.
The
.Cm unblock
and
.Cm block
options become a simple file copy.
.Pp
After completion,
.Nm
reports the number of whole and partial input and output blocks.
.Sh OPERANDS
The following operands are supported:
.Bl -tag -width "if=file"
.It Cm if= Ns Ar file
.Pp
Specifies the input path.
Standard input is the default.
.It Cm of= Ns Ar file
.Pp
Specifies the output path.
Standard output is the default.
If the
.Cm seek Ns = Ns Ar expr
conversion is not also specified, the output file will be truncated before
the copy begins, unless
.Cm conv Ns = Ns Ar notrunc
is specified.
If
.Cm seek Ns = Ns Ar expr
is specified, but
.Cm conv Ns = Ns Ar notrunc
is not, the effect of the copy will be to preserve the blocks in the output
file over which
.Nm
seeks, but no other portion of the output file will be preserved.
(If the size of the seek plus the size of the input file is less than the
previous size of the output file, the output file is shortened by the copy.)
.It Cm ibs Ns = Ns Ar n
.Pp
Specifies the input block size in
.Ar n
bytes (default is 512).
.It Cm obs Ns = Ns Ar n
.Pp
Specifies the output block size in
.Ar n
bytes (default is 512).
.It Cm bs Ns = Ns Ar n
.Pp
Sets both input and output block sizes to
.Ar n
bytes, superseding
.Cm ibs Ns =
and
.Cm obs Ns = .
If no conversion other than
.Cm sync ,
.Cm noerror ,
and
.Cm notrunc
is specified, each input block is copied to the output as a
single block without aggregating short blocks.
.It Cm cbs Ns = Ns Ar n
.Pp
Specifies the conversion block size for
.Cm block
and
.Cm unblock
in bytes by
.Ar n
(default is
.Cm 0 Ns ).
If
.Cm cbs Ns =
is omitted or given a value of
.Cm 0 ,
using
.Cm block
or
.Cm unblock
produces unspecified results.
.Pp
This option is used only if
.Cm ASCII
or
.Cm EBCDIC
conversion is specified.
For the
.Cm ascii
and
.Cm asciib
operands, the input is handled as described for the
.Cm unblock
operand except that characters are converted to
.Cm ASCII
before the trailing
.Cm SPACE
characters are deleted.
For the
.Cm ebcdic ,
.Cm ebcdicb ,
.Cm ibm ,
and
.Cm ibmb
operands, the input is handled as described for the
.Cm block
operand except that the characters are converted to
.Cm EBCDIC
or IBM
.Cm EBCDIC
after the trailing
.Cm SPACE
characters are added.
.It Cm files Ns = Ns Ar n
.Pp
Copies and concatenates
.Ar n
input files before terminating (makes sense
only where input is a magnetic tape or similar device).
.It Cm skip Ns = Ns Ar n
.Pp
Skips
.Ar n
input blocks (using the specified input block size) before starting to copy.
On seekable files, the implementation reads the blocks or seeks past them.
On non-seekable files, the blocks are read and the data is discarded.
.It Cm iseek Ns = Ns Ar n
.Pp
Seeks
.Ar n
blocks from beginning of input file before copying (appropriate
for disk files, where
.Cm skip
can be incredibly slow).
.It Cm oseek Ns = Ns Ar n
.Pp
Seeks
.Ar n
blocks from beginning of output file before copying.
.It Cm seek Ns = Ns Ar n
.Pp
Skips
.Ar n
blocks (using the specified output block size) from beginning of
output file before copying.
On non-seekable files, existing blocks are read and space from the current
end-of-file to the specified offset, if any, is filled with null bytes.
On seekable files, the implementation seeks to the specified
offset or reads the blocks as described for non-seekable files.
.It Cm ostride Ns = Ns Ar n
.Pp
Writes every
.Ar n Ns
th block (using the specified output block size) when writing output.
Skips
.Ar n
- 1 blocks after writing each record.
.It Cm istride Ns = Ns Ar n
.Pp
Reads every
.Ar n Ns
th block (using the specified input block size) when reading input.
Skips
.Ar n
- 1 blocks after reading each record.
.It Cm stride Ns = Ns Ar n
.Pp
Reads every
.Ar n Ns
th block (using the specified input block size) when reading input.
Skips
.Ar n
- 1 blocks after reading each record.
Also writes every
.Ar n Ns
th block (using the specified output block size) when writing output.
Skips
.Ar n
- 1 blocks after writing each record.
.It Cm count Ns = Ns Ar n
.Pp
Copies only
.Ar n
input blocks.
.It Cm conv Ns = Ns Ar value Ns Op , Ns Ar value Ns ...
.Pp
Where
.Ar value Ns
s are comma-separated symbols from the following list:
.Bl -hang
.It Cm ascii
Converts
.Cm EBCDIC
to
.Cm ASCII .
.sp
.It Cm asciib
Converts
.Cm EBCDIC
to
.Cm ASCII
using
.Cm BSD Ns
-compatible character translations.
.It Cm ebcdic
Converts
.Cm ASCII
to
.Cm EBCDIC .
If converting fixed-length
.Cm ASCII
records without
.Cm NEWLINE Ns
s, sets up a pipeline with
.Nm
.Cm conv Ns = Ns Ar unblock
beforehand.
.It Cm ebcdicb
Converts
.Cm ASCII
to
.Cm EBCDIC
using
.Cm BSD Ns
-compatible character translations.
If converting fixed-length
.Cm ASCII
records without
.Cm NEWLINE Ns
s, sets up a pipeline with
.Nm
.Cm conv Ns = Ns Ar unblock
beforehand.
.It Cm ibm
Slightly different map of
.Cm ASCII
to
.Cm EBCDIC .
If converting fixed-length
.Cm ASCII
records without
.Cm NEWLINE Ns
s, sets up a pipeline with
.Nm
.Cm conv Ns = Ns Ar unblock
beforehand.
.It Cm ibmb
Slightly different map of
.Cm ASCII
to
.Cm EBCDIC
using
.Cm BSD Ns
-compatible character translations.
If converting fixed-length
.Cm ASCII
records without
.Cm NEWLINE Ns
s, sets up a pipeline with
.Nm
.Cm conv Ns = Ns Ar unblock
beforehand.
.El
.Pp
The
.Cm ascii
(or
.Cm asciib Ns ),
.Cm ebcdic
(or
.Cm ebcdicb Ns ),
and
.Cm ibm
(or
.Cm ibmb )
values are mutually exclusive.
.Bl -hang
.It Cm block
Treats the input as a sequence of
.Cm NEWLINE Ns
-terminated or
.Cm EOF Ns
-terminated variable-length records independent of the input block boundaries.
Each record is converted to a record with a fixed length specified
by the conversion block size.
Any
.Cm NEWLINE
character is removed from the input line.
.Cm SPACE
characters are appended to lines that are shorter than their conversion block
size to fill the block.
Lines that are longer than the conversion block size are truncated to the
largest number of characters that will fit into that size.
The number of truncated lines is reported.
.It Cm unblock
Converts fixed-length records to variable length.
Reads a number of bytes equal to the conversion block size (or the number of
bytes remaining in the input, if less than the conversion block size),
delete all trailing
.Cm SPACE
characters, and append a
.Cm NEWLINE
character.
.El
.Pp
The
.Cm block
and
.Cm unblock
values are mutually exclusive.
.Bl -hang
.It Cm lcase
Maps upper-case characters specified by the
.Cm LC_CTYPE
keyword
.Cm tolower
to the corresponding lower-case character.
Characters for which no mapping is specified are not modified by this
conversion.
.It Cm ucase
Maps lower-case characters specified by the
.Cm LC_CTYPE
keyword
.Cm toupper
to the corresponding upper-case character.
Characters for which no mapping is specified are not modified by this
conversion.
.El
.Pp
The
.Cm lcase
and
.Cm ucase
symbols are mutually exclusive.
.Bl -hang
.It Cm swab
Swaps every pair of input bytes.
If the current input record is an odd number of bytes, the last byte in the
input record is ignored.
.It Cm noerror
Does not stop processing on an input error.
When an input error occurs, a diagnostic message is written on standard error,
followed by the current input and output block counts in the same format as
used at completion.
If the
.Cm sync
conversion is specified, the missing input is replaced with null
bytes and processed normally.
Otherwise, the input block will be omitted from the output.
.It Cm notrunc
Does not truncate the output file.
Preserves blocks in the output file not explicitly written by this invocation
of
.Nm .
(See also the preceding
.Cm of Ns = Ns Ar file
operand.)
.It Cm sync
Pads every input block to the size of the
.Cm ibs Ns =
buffer, appending null bytes.
(If either
.Cm block
or
.Cm unblock
is also specified, appends
.Cm SPACE
characters, rather than null bytes.)
.El
.It Cm iflag Ns = Ns Ar value Ns Op , Ns Ar value ...
.Pp
Where
.Ar value Ns
s are comma-separated symbols from the following list which
affect the behavior of reading from the input file:
.Bl -hang
.It Cm fullblock
Accumulate full blocks of input.
.El
.It Cm oflag Ns = Ns Ar value Ns Op , Ns Ar value ...
.ad
.sp .6
Where
.Ar value Ns
s are comma-separated symbols from the following list which
affect the behavior of writing the output file:
.Bl -hang
.It Cm dsync
The output file is opened with the
.Cm O_DSYNC
flag set.
All data writes will be synchronous.
For more information on
.Cm O_DSYNC
see
.Xr fcntl.h 3HEAD .
.It Cm sync
The output file is opened with the
.Cm O_SYNC .
All data and metadata writes will be synchronous.
For more information on
.Cm O_SYNC
see
.Xr fcntl.h 3HEAD .
.El
.It Cm status Ns = Ns Ar type
Changes the way that
.Nm
outputs information about transfers.
Only one
.Ar type may be specified.
The following are valid values for
.Ar type :
.Bl -hang
.It Cm none
The program will not output any information and statistics about the transfer.
This includes when
.Nm
receives a signal such as
.Dv SIGINFO
and
.Dv SIGUSR1 .
Only errors will be emitted.
.It Cm noxfer
When printing statistical information such as when the program terminates or in
response to a signal, only print information about the number of records and
none of the statistics about the transfer
.Pq total bytes, total time, and throughput .
.It Cm progress
Once a second, output the normal
.Nm
transfer statistics that include the total number of bytes transferred, time
elapsed, and average throughput.
.El
.El
.Pp
If operands other than
.Cm conv Ns =
and
.Cm oflag Ns =
are specified more than once, the last specified
.Cm operand Ns = Ns Ar value
is used.
.Pp
For the
.Cm bs Ns = ,
.Cm cbs Ns = ,
.Cm ibs Ns = ,
and
.Cm obs Ns =
operands, the application must supply an expression specifying a size in bytes.
The expression,
.Cm expr ,
can be:
.Bl -enum -offset indent -compact
.It
a positive decimal number
.Pp
.It
a positive decimal number followed by
.Sy k ,
specifying multiplication by 1024
.Pp
.It
a positive decimal number followed by
.Sy M ,
specifying multiplication by 1024*1024
.Pp
.It
a positive decimal number followed by
.Sy G ,
specifying multiplication by 1024*1024*1024
.Pp
.It
a positive decimal number followed by
.Sy T ,
specifying multiplication by 1024*1024*1024*1024
.Pp
.It
a positive decimal number followed by
.Sy P ,
specifying multiplication by 1024*1024*1024*1024*1024
.Pp
.It
a positive decimal number followed by
.Sy E ,
specifying multiplication by 1024*1024*1024*1024*1024*1024
.Pp
.It
a positive decimal number followed by
.Sy Z ,
specifying multiplication by 1024*1024*1024*1024*1024*1024*1024
.Pp
.It
a positive decimal number followed by
.Sy b ,
specifying multiplication by 512
.Pp
.It
two or more positive decimal numbers (with or without
.Sy k
or
.Sy b )
separated by
.Sy x ,
specifying the product of the indicated values.
.El
.Pp
All of the operands will be processed before any input is read.
.Sh SIGNALS
When
.Nm
receives either SIGINFO or SIGUSR1,
.Nm
will emit the current input and output block counts, total bytes written,
total time elapsed, and the number of bytes per second to standard error.
This is the same information format that
.Nm
emits when it successfully completes.
Users may send SIGINFO via their terminal.
The default character is ^T, see
.Xr stty 1
for more information.
.Pp
For
.Sy SIGINT ,
.Nm
writes status information to standard error before exiting.
.Nm
takes the standard action for all other signals.
.Sh USAGE
See
.Xr largefile 7
for the description of the behavior of
.Nm
when encountering files greater than or equal to 2 Gbyte (2^31 bytes).
.Sh EXIT STATUS
The following exit values are returned:
.Bl -tag -width ".It Cm >0"
.It Cm 0
The input file was copied successfully.
.It Cm >0
An error occurred.
.El
.Pp
If an input error is detected and the
.Cm noerror
conversion has not been specified, any partial output block will be written
to the output file, a diagnostic message will be written, and the copy
operation will be discontinued.
If some other error is detected, a diagnostic message will be
written and the copy operation will be discontinued.
.Sh EXAMPLES
.Bl -ohang
.It Sy Example 1 No Copying from one tape drive to another
.Pp
The following example copies from tape drive
.Sy 0
to tape drive
.Sy 1 ,
using a common historical device naming convention.
.Pp
.Dl % dd if=/dev/rmt/0h of=/dev/rmt/1h
.It Sy Example 2 No Stripping the first 10 bytes from standard input
.Pp
The following example strips the first 10 bytes from standard input:
.Pp
.Dl % dd ibs=10 skip=1
.It Sy Example 3 No Reading a tape into an ASCII file
.Pp
This example reads an
.Cm EBCDIC
tape blocked ten 80-byte
.Cm EBCDIC
card images per block into the
.Cm ASCII
file
.Sy x :
.Pp
.Dl % dd if=/dev/tape of=x ibs=800 cbs=80 conv=ascii,lcase
.It Sy Example 4 No Using conv=sync to write to tape
.Pp
The following example uses
.Cm conv Ns = Ns Ar sync
when writing to a tape:
.Pp
.Dl % tar cvf - . | compress | dd obs=1024k of=/dev/rmt/0 conv=sync
.El
.Sh DIAGNOSTICS
.Bl -hang
.It Sy f+p records in(out)
numbers of full and partial blocks read(written)
.El
.Sh ENVIRONMENT VARIABLES
See
.Xr environ 7
for descriptions of the following environment variables
that affect the execution of
.Nm :
.Ev LANG ,
.Ev LC_ALL ,
.Ev LC_CTYPE ,
.Ev LC_MESSAGES ,
and
.Ev NLSPATH .
.Sh INTERFACE STABILITY
Standard
.Sh SEE ALSO
.Xr cp 1 ,
.Xr sed 1 ,
.Xr tr 1 ,
.Xr fcntl.h 3HEAD ,
.Xr attributes 7 ,
.Xr environ 7 ,
.Xr largefile 7 ,
.Xr standards 7
.Sh NOTES
Do not use
.Nm
to copy files between file systems having different block sizes.
.Pp
Using a blocked device to copy a file will result in extra nulls being added
to the file to pad the final block to the block boundary.
.Pp
When
.Nm
reads from a pipe, using the
.Cm ibs Ns = Ns Ar X
and
.Cm obs Ns = Ns Ar Y
operands, the output will always be blocked in chunks of size Y.
When
.Cm bs Ns = Ns Ar Z
is used, the output blocks will be whatever was available to be read
from the pipe at the time.
.Pp
When using
.Nm
to copy files to a tape device, the file size must be a multiple of the
device sector size (for example, 512 Kbyte).
To copy files of arbitrary size to a tape device, use
.Xr tar 1
or
.Xr cpio 1 .
|