DD(1POSIX)
Okay bestie, welcome to the DD(1POSIX) page from the POSIX Programmer's Manual! ๐โจ
๐ซ PROLOG ๐ซ
Real talk: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ โ so consult the corresponding Linux manual page for details on Linux behavior โ or the interface may not be implemented on Linux at all. No cap, that's the whole tea. ๐ซถ
๐ NAME ๐
dd โ convert and copy a file
โจ SYNOPSIS โจ
dd [operand...]
๐ฆ DESCRIPTION ๐ฆ
Okay so here's the vibe: the dd utility is gonna copy the specified input file to the specified output file, and it can do conversions along the way using specific input and output block sizes. It reads the input one block at a time, using the specified input block size. Then it processes the block of data that actually got returned โ and yes, bestie, that block could be smaller than the requested block size. It applies any conversions that have been specified and writes the resulting data to the output in blocks of the specified output block size.
If the bs=expr operand is specified and no conversions other than sync, noerror, or notrunc are requested, then the data returned from each input block shall be written as a separate output block. If the read returns less than a full block and the sync conversion is not specified, the resulting output block shall be the same size as the input block. If the bs=expr operand is not specified, or a conversion other than sync, noerror, or notrunc is requested, the input shall be processed and collected into full-sized output blocks until the end of the input is reached. Periodt. ๐
The processing order goes like this, bestie:
- An input block is read. Step one, iconic.
- If that input block is shorter than the specified input block size and you specified the
syncconversion, null bytes get appended to the input data until it hits the specified size. (If eitherblockorunblockis also specified,<space>characters get appended instead of null bytes.) The remaining conversions and output include those pad characters as if they had been read from the input. Pads are treated like real input data, bestie. ๐ซถ - If
bs=expris specified and no conversion other thansyncornoerroris requested, the resulting data gets written to the output as a single block, and the remaining steps are omitted. We skip the rest. Bye. ๐ - If the
swabconversion is specified, each pair of input data bytes gets swapped. If the input block has an odd number of bytes, the last byte in the input record is not swapped. Odd one out stays unswapped. ๐ - Any remaining conversions (
block,unblock,lcase, anducase) get performed. These conversions operate on the input data independently of the input blocking; an input or output fixed-length record may span block boundaries. Records can cross block boundaries, no cap. ๐ - The data resulting from input or conversion or both gets aggregated into output blocks of the specified size. After the end of input is reached, any remaining output gets written as a block without padding if
conv=syncis not specified; so the final output block may be shorter than the output block size. Final block can be short. That's the vibe. ๐
๐ OPTIONS ๐
None. That's it. No flags, no options, just vibes. โจ
๐ธ OPERANDS ๐ธ
okay bestie this is the part where you actually tell dd what to do โ every single one of these operands gets processed before any input is read, which is iconic of it honestly.
if=file โ names the input pathname. Default is standard input. ๐of=file โ names the output pathname. Default is standard output.
So here's the tea on truncation: if seek=expr is not also specified, the output file gets truncated before the copy begins โ but only if you actually wrote an explicit of=file operand โ and that's unless conv=notrunc is specified. ๐ซฃ
If seek=expr is specified but conv=notrunc isn't, then the copy preserves the blocks in the output file over which dd seeks, and literally no other portion of the output file shall be preserved. Like, the rest? gone. Not preserved. Bye. ๐ญ
- 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 shall be shortened by the copy.
- If the input file is empty and either the size of the seek is greater than the previous size of the output file or the output file didn't previously exist, the size of the output file shall be set to the file offset after the seek.
ibs=expr โ input block size, in bytes, per expr. Default is512. โจobs=expr โ output block size, in bytes, per expr. Default is512. โจbs=expr โ sets both input and output block sizes to expr bytes, and it supersedesibs=andobs=. If no conversion other thansync,noerror, andnotruncis specified, each input block shall be copied to the output as a single block without aggregating short blocks. ๐cbs=expr โ conversion block size forblockandunblock, in bytes, per expr. Default is zero.
โ ๏ธ Ifcbs=is omitted or given a value of zero, usingblockorunblockproduces unspecified results. Not a vibe, bestie, don't do it.
The application shall ensure that this operand is also specified if the conv= operand is specified with a value of ascii, ebcdic, or ibm.
- For a
conv=operand with anasciivalue, the input is handled as described for theunblockvalue, except that characters are converted to ASCII before any trailing<space>characters are deleted. - For
conv=operands withebcdicoribmvalues, the input is handled as described for theblockvalue, except that the characters are converted to EBCDIC or IBM EBCDIC, respectively, after any trailing<space>characters are added.
skip=n โ skip n input blocks (using the specified input block size) before starting to copy. On seekable files, the implementation shall read the blocks or seek past them; on non-seekable files, the blocks shall be read and the data shall be discarded. ๐ฆseek=n โ skip n blocks (using the specified output block size) from the beginning of the output file before copying.- On non-seekable files, existing blocks shall be read and space from the current end-of-file to the specified offset, if any, filled with null bytes.
- On seekable files, the implementation shall seek to the specified offset or read the blocks as described for non-seekable files.
count=n โ copy only n input blocks. If n is zero, it is unspecified whether no blocks or all blocks are copied. ๐คทโ๏ธconv=value[,value ...] โ where values are<comma>-separated symbols from this list, and every single one of them matters:asciiโ convert EBCDIC to ASCII; see Table 4-7, ASCII to EBCDIC Conversion.ebcdicโ convert ASCII to EBCDIC; see Table 4-7, ASCII to EBCDIC Conversion.ibmโ convert ASCII to a different EBCDIC set; see Table 4-8, ASCII to IBM EBCDIC Conversion.
๐ Theascii,ebcdic, andibmvalues are mutually-exclusive. Pick ONE.
blockโ treat the input as a sequence of<newline>-terminated or end-of-file-terminated variable-length records, independent of the input block boundaries. Each record shall be converted to a record with a fixed length specified by the conversion block size. Any<newline>shall be removed from the input line;<space>characters shall be appended to lines that are shorter than their conversion block size to fill the block. Lines that are longer than the conversion block size shall be truncated to the largest number of characters that fit into that size; the number of truncated lines shall be reported (see the STDERR section). ๐
๐จ Theblockandunblockvalues are mutually-exclusive.
unblockโ convert fixed-length records to variable length. Read 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<space>characters, and append a<newline>. ๐lcaseโ map uppercase characters specified by theLC_CTYPEkeywordtolowerto the corresponding lowercase character. Characters for which no mapping is specified shall not be modified by this conversion.
๐จ Thelcaseanducasesymbols are mutually-exclusive.
ucaseโ map lowercase characters specified by theLC_CTYPEkeywordtoupperto the corresponding uppercase character. Characters for which no mapping is specified shall not be modified by this conversion. โจswabโ swap every pair of input bytes. Just. Swap 'em. ๐noerrorโ do not stop processing on an input error. When an input error occurs, a diagnostic message shall be written on standard error, followed by the current input and output block counts in the same format as used at completion (see the STDERR section). If thesyncconversion is specified, the missing input shall be replaced with null bytes and processed normally; otherwise, the input block shall be omitted from the output.notruncโ do not truncate the output file. Preserve blocks in the output file not explicitly written by this invocation of theddutility. (See also the precedingof=fileoperand.) ๐ซถsyncโ pad every input block to the size of theibs=buffer, appending null bytes. (If eitherblockorunblockis also specified, append<space>characters, rather than null bytes.) ๐
โ ๏ธ The behavior is unspecified if operands other than conv= are specified more than once. One and done, bestie.
โจ the expr situation โจ
For the bs=, cbs=, ibs=, and obs= operands, the application shall supply an expression specifying a size in bytes. That expression, expr, can be:
- A positive decimal number
- A positive decimal number followed by
k, specifying multiplication by 1024 - A positive decimal number followed by
b, specifying multiplication by 512 - Two or more positive decimal numbers (with or without
korb) separated byx, specifying the product of the indicated values
All of the operands are processed before any input is read. (Yes, again. It's that serious.)
๐ the tables ๐
The following two tables display the octal number character values used for the ascii and ebcdic conversions (first table) and for the ibm conversion (second table). In both tables, the ASCII values are the row and column headers and the EBCDIC values are found at their intersections.
For example, ASCII 0012 (LF) is the second row, third column, yielding 0045 in EBCDIC. ๐ฏ
The inverted tables (for EBCDIC to ASCII conversion) are not shown, but are in one-to-one correspondence with these tables. The differences between the two tables are highlighted by small boxes drawn around five entries.
Table 4-7: ASCII to EBCDIC Conversion
Table 4-8: ASCII to IBM EBCDIC Conversion
๐ง STDIN
If no if= operand is specified, the standard input shall be used. See the INPUT FILES section. ๐
๐ INPUT FILES
The input file can be any file type. Any. File. Type. No gatekeeping. ๐
๐ง ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of dd:
LANGโ provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLโ if set to a non-empty string value, override the values of all the other internationalization variables.LC_CTYPEโ determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files), the classification of characters as uppercase or lowercase, and the mapping of characters from one case to the other.LC_MESSAGESโ determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.NLSPATHโ determine the location of message catalogs for the processing ofLC_MESSAGES.
โก ASYNCHRONOUS EVENTS
For SIGINT, the dd utility shall interrupt its current processing, write status information to standard error, and exit as though terminated by SIGINT. ๐ข
It shall take the standard action for all other signals; see the ASYNCHRONOUS EVENTS section in Section 1.4, Utility Description Defaults.
๐ STDOUT
If no of= operand is specified, the standard output shall be used. The nature of the output depends on the operands selected. Mysterious. Iconic. Depends entirely on your choices, bestie.
๐ฌ STDERR ๐ฌ
okay so when it's all done, dd is gonna spill the tea to standard error: how many input blocks and output blocks it dealt with. In the POSIX locale it uses these exact formats:
"%u+%u records in\n", <number of whole input blocks>,
<number of partial input blocks>
"%u+%u records out\n", <number of whole output blocks>,
<number of partial output blocks>
so like, what even is a partial block bestie? A partial input block is one where read() came back with less than the input block size. A partial output block is one that got written with fewer bytes than the output block size said. so unserious of it. ๐
also!! if there's at least one truncated block, the number of truncated blocks gets written to standard error too. In the POSIX locale the format is:
"%u truncated %s\n", <number of truncated blocks>, "record" (if
<number of truncated blocks> is one) "records" (otherwise)
like yes grammar matters even in your error output periodt. โจ
and yeah, diagnostic messages can also be written to standard error. obviously. that's its whole job.
๐ OUTPUT FILES ๐
if you used the of= operand, the output is literally the same as what's described in the STDOUT section. same vibe, different file, no cap.
๐ฆ EXTENDED DESCRIPTION ๐ฆ
None. that's it. nothing. empty. the void. not a single thing to report bestie ๐ซถ
๐ช EXIT STATUS ๐ช
here's what you can get back:
0โ the input file was copied successfully. ate and left no crumbs. ๐>0โ an error occurred. it's giving chaos. ๐ญ
๐ฅ CONSEQUENCES OF ERRORS ๐ฅ
so if an input error gets detected and you did not specify the noerror conversion, then: any partial output block gets written to the output file, a diagnostic message gets written, and the copy operation gets discontinued. that's it, we're done here, packing up. ๐งณ
if some other error gets detected, a diagnostic message gets written and the copy operation gets discontinued. same energy. ๐ฅ
The following sections are informative. so like, read them for the lore, not the law. ๐
๐ธ APPLICATION USAGE ๐ธ
you can set the input and output block size to take advantage of raw physical I/O. optimization era โจ
also important: there are so many different versions of the EBCDIC codesets, it's honestly a lot. The ASCII and EBCDIC conversions specified for the dd utility perform conversions for the version specified by the tables. iykyk.
๐ EXAMPLES ๐
okay bestie, watch this. this command:
dd if=/dev/rmt0h of=/dev/rmt1h
copies from tape drive 0 to tape drive 1, using a common historical device naming convention. vintage but make it slay. ๐ผ
and this command:
dd ibs=10 skip=1
strips the first 10 bytes from standard input. literally just takes them out. bye. ๐
and this example reads an EBCDIC tape blocked ten 80-byte EBCDIC card images per block into the ASCII file x:
dd if=/dev/tape of=x ibs=800 cbs=80 conv=ascii,lcase
look at all those conversions working together. teamwork makes the dream work fr fr. ๐ซถ
๐ง RATIONALE ๐ง
so the OPTIONS section says ``None'' because there are no options recognized by historical dd utilities. like, none. zero. zilch. and yeah, sure, lots of the operands could have been designed to use the Utility Syntax Guidelines, which would have given us the classic hyphenated option letters. but in this version of this volume of POSIX.1โ2017, dd retains its curious JCL-like syntax because a huge number of applications depend on the historical implementation. so we keep the weird little syntax. it's iconic, don't touch it. ๐
a suggested implementation technique for conv=noerror,sync is to zero (or <space>-fill, if blocking or unblocking) the input buffer before each read, and to write the contents of the input buffer to the output even after an error. this way, any data transferred to the input buffer before the error was detected is preserved. preservation queen. โจ
another point: a failed read on a regular file or a disk generally does not increment the file offset, and dd must then seek past the block on which the error occurred โ otherwise the input error occurs repetitively. forever. an infinite loop of suffering. ๐ญ but when the input is a magnetic tape, the tape normally has already passed the block containing the error when the error is reported, so no seek is necessary. different rules for different girlies.
the default ibs= and obs= sizes are specified as 512 bytes because there are historical (largely portable) scripts that assume these values. if they were left unspecified, unusual results could occur if an implementation chose an odd block size. unusual results is not the vibe we're going for. ๐
historical implementations of dd used creat() when processing of=file. this makes the seek= operand unusable except on special files. the conv=notrunc feature was added because more recent BSD-based implementations use open() (without O_TRUNC) instead of creat(), but they fail to delete output file contents after the data copied. messy. ๐
the w multiplier (historically meaning word), is used in System V to mean 2 and in 4.2 BSD to mean 4. Since word is inherently non-portable, its use is not supported by this volume of POSIX.1โ2017. so don't. just don't. ๐ซ
Standard EBCDIC does not have the characters '[' and ']'. The values used in the table are taken from a common print train that does contain them. Other than those characters, the print train values are not filled in, but appear to provide some of the motivation for the historical choice of translations reflected here.
The Standard EBCDIC table provides a 1:1 translation for all 256 bytes.
The IBM EBCDIC table does not provide such a translation. The marked cells in the tables differ in such a way that:
- EBCDIC
0112('ยข') and0152(broken pipe) do not appear in the table. - EBCDIC
0137('ยฌ') translates to/from ASCII0236('^'). In the standard table, EBCDIC0232(no graphic) is used. - EBCDIC
0241('~') translates to/from ASCII0176('~'). In the standard table, EBCDIC0137('ยฌ') is used. 0255('[') and0275(']') appear twice, once in the same place as for the standard table and once in place of0112('ยข') and0241('~').
in net result:
EBCDIC 0275 (']') displaced EBCDIC 0241 ('~') in cell 0345.
That displaced EBCDIC 0137 ('ยฌ') in cell 0176.
That displaced EBCDIC 0232 (no graphic) in cell 0136.
That replaced EBCDIC 0152 (broken pipe) in cell 0313.
EBCDIC 0255 ('[') replaced EBCDIC 0112 ('ยข').
it's giving domino effect. one thing knocked over the next and suddenly we have a whole translation table crisis. ๐
this translation, however, reflects historical practice that (ASCII) '~' and 'ยฌ' were often mapped to each other, as were '[' and 'ยข'; and ']' and (EBCDIC) '~'.
the cbs operand is required if any of the ascii, ebcdic, or ibm operands are specified. required bestie, don't forget it. for the ascii operand, the input is handled as described for the unblock operand except that characters are converted to ASCII before the trailing <space> characters are deleted. for the ebcdic and ibm operands, the input is handled as described for the block operand except that the characters are converted to EBCDIC or IBM EBCDIC after the trailing <space> characters are added. order matters!! โจ
the block and unblock keywords are from historical BSD practice. the lore runs deep. ๐ฆ
the consistent use of the word record in standard error messages matches most historical practice. an earlier version of System V used block, but this has been updated in more recent releases. glow up. ๐
early proposals only allowed two numbers separated by x to be used in a product when specifying bs=, cbs=, ibs=, and obs= sizes. this was changed to reflect the historical practice of allowing multiple numbers in the product as provided by Version 7 and all releases of System V and BSD. more numbers, more fun. ๐ฅ
a change to the swab conversion is required to match historical practice and is the result of IEEE PASC Interpretations 1003.2 #03 and #04, submitted for the ISO POSIXโ2:1993 standard.
a change to the handling of SIGINT is required to match historical practice and is the result of IEEE PASC Interpretation 1003.2 #06 submitted for the ISO POSIXโ2:1993 standard.
๐ฎ FUTURE DIRECTIONS ๐ฎ
None. nothing coming. the future is empty. manifesting nothing. ๐ซถ
๐ SEE ALSO ๐
- Section 1.4, Utility Description Defaults,
sed,tr - The Base Definitions volume of POSIX.1โ2017, Chapter 8, Environment Variables
go read those if you want the full cinematic universe. ๐
โญ COPYRIGHT โญ
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version 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 .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's a wrap on dd(1POSIX) bestie!! ๐ this page came from IEEE/The Open Group, dated 2017, and the manual page itself is DD(1POSIX). you read the whole thing, you're literally a Unix icon now, no cap. go copy some blocks. mwah. ๐
โจ๐
๐ฆ where this page comes from
- debian bookworm: manpages-posix 2017a-2 ยท Other
- debian trixie: manpages-posix 2017a-2 ยท Other
- ubuntu jammy: manpages-posix 2017a-2 ยท Other
- ubuntu noble: manpages-posix 2017a-2 ยท Other
- ubuntu resolute: manpages-posix 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms