{
    "mode": "info",
    "parameter": "dd",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/dd/json",
    "generated": "2026-11-10T07:37:02Z",
    "sections": {
        "File: coreutils.info,  Node: dd invocation,  Next: install invocation,  Prev: cp invocation,  Up: Basic operations": {
            "content": "",
            "subsections": [
                {
                    "name": "11.2 'dd': Convert and copy a file",
                    "content": "'dd' copies input to output with a changeable I/O block size, while\noptionally performing conversions on the data.  Synopses:\n\ndd [OPERAND]...\ndd OPTION\n\nThe only options are '--help' and '--version'.  *Note Common\noptions::.\n\nBy default, 'dd' copies standard input to standard output.  To copy,\n'dd' repeatedly does the following steps in order:\n\n1. Read an input block.\n\n2. If converting via 'sync', pad as needed to meet the input block\nsize.  Pad with spaces if converting via 'block' or 'unblock', NUL\nbytes otherwise.\n\n3. If 'bs=' is given and no conversion mentioned in steps (4) or (5)\nis given, output the data as a single block and skip all remaining\nsteps.\n\n4. If the 'swab' conversion is given, swap each pair of input bytes.\nIf the input data length is odd, preserve the last input byte\n(since there is nothing to swap it with).\n\n5. If any of the conversions 'swab', 'block', 'unblock', 'lcase',\n'ucase', 'ascii', 'ebcdic' and 'ibm' are given, do these\nconversions.  These conversions operate independently of input\nblocking, and might deal with records that span block boundaries.\n\n6. Aggregate the resulting data into output blocks of the specified\nsize, and output each output block in turn.  Do not pad the last\noutput block; it can be shorter than usual.\n\n'dd' accepts the following operands, whose syntax was inspired by the\nDD (data definition) statement of OS/360 JCL.\n\n'if=FILE'\nRead from FILE instead of standard input.\n\n'of=FILE'\nWrite to FILE instead of standard output.  Unless 'conv=notrunc' is\ngiven, truncate FILE before writing it.\n\n'ibs=BYTES'\nSet the input block size to BYTES.  This makes 'dd' read BYTES per\nblock.  The default is 512 bytes.\n\n'obs=BYTES'\nSet the output block size to BYTES.  This makes 'dd' write BYTES\nper block.  The default is 512 bytes.\n\n'bs=BYTES'\nSet both input and output block sizes to BYTES.  This makes 'dd'\nread and write BYTES per block, overriding any 'ibs' and 'obs'\nsettings.  In addition, if no data-transforming 'conv' operand is\nspecified, input is copied to the output as soon as it's read, even\nif it is smaller than the block size.\n\n'cbs=BYTES'\nSet the conversion block size to BYTES.  When converting\nvariable-length records to fixed-length ones ('conv=block') or the\nreverse ('conv=unblock'), use BYTES as the fixed record length.\n\n'skip=N'\n'iseek=N'\nSkip N 'ibs'-byte blocks in the input file before copying.  If N\nends in the letter 'B', interpret N as a byte count rather than a\nblock count.  ('B' and the 'iseek=' spelling are GNU extensions to\nPOSIX.)\n\n'seek=N'\n'oseek=N'\nSkip N 'obs'-byte blocks in the output file before truncating or\ncopying.  If N ends in the letter 'B', interpret N as a byte count\nrather than a block count.  ('B' and the 'oseek=' spelling are GNU\nextensions to POSIX.)\n\n'count=N'\nCopy N 'ibs'-byte blocks from the input file, instead of everything\nuntil the end of the file.  If N ends in the letter 'B', interpret\nN as a byte count rather than a block count; this is a GNU\nextension to POSIX. If short reads occur, as could be the case when\nreading from a pipe for example, 'iflag=fullblock' ensures that\n'count=' counts complete input blocks rather than input read\noperations.  As an extension to POSIX, 'count=0' copies zero blocks\ninstead of copying all blocks.\n\n'status=LEVEL'\nSpecify the amount of information printed.  If this operand is\ngiven multiple times, the last one takes precedence.  The LEVEL\nvalue can be one of the following:\n\n'none'\nDo not print any informational or warning messages to standard\nerror.  Error messages are output as normal.\n\n'noxfer'\nDo not print the final transfer rate and volume statistics\nthat normally make up the last status line.\n\n'progress'\nPrint the transfer rate and volume statistics on standard\nerror, when processing each input block.  Statistics are\noutput on a single line at most once every second, but updates\ncan be delayed when waiting on I/O.\n\nTransfer information is normally output to standard error upon\nreceipt of the 'INFO' signal or when 'dd' exits, and defaults to\nthe following form in the C locale:\n\n7287+1 records in\n116608+0 records out\n59703296 bytes (60 MB, 57 MiB) copied, 0.0427974 s, 1.4 GB/s\n\nThe notation 'W+P' stands for W whole blocks and P partial blocks.\nA partial block occurs when a read or write operation succeeds but\ntransfers less data than the block size.  An additional line like\n'1 truncated record' or '10 truncated records' is output after the\n'records out' line if 'conv=block' processing truncated one or more\ninput records.\n\nThe 'status=' operand is a GNU extension to POSIX.\n\n'conv=CONVERSION[,CONVERSION]...'\nConvert the file as specified by the CONVERSION argument(s).  (No\nspaces around any comma(s).)\n\nConversions:\n\n'ascii'\nConvert EBCDIC to ASCII, using the conversion table specified\nby POSIX.  This provides a 1:1 translation for all 256 bytes.\nThis implies 'conv=unblock'; input is converted to ASCII\nbefore trailing spaces are deleted.\n\n'ebcdic'\nConvert ASCII to EBCDIC.  This is the inverse of the 'ascii'\nconversion.  This implies 'conv=block'; trailing spaces are\nadded before being converted to EBCDIC.\n\n'ibm'\nThis acts like 'conv=ebcdic', except it uses the alternate\nconversion table specified by POSIX.  This is not a 1:1\ntranslation, but reflects common historical practice for '~',\n'[', and ']'.\n\nThe 'ascii', 'ebcdic', and 'ibm' conversions are mutually\nexclusive.  If you use any of these conversions, you should\nalso use the 'cbs=' operand.\n\n'block'\nFor each line in the input, output 'cbs' bytes, replacing the\ninput newline with a space and truncating or padding input\nlines with spaces as necessary.\n\n'unblock'\nRemove any trailing spaces in each 'cbs'-sized input block,\nand append a newline.\n\nThe 'block' and 'unblock' conversions are mutually exclusive.\nIf you use either of these conversions, you should also use\nthe 'cbs=' operand.\n\n'lcase'\nChange uppercase letters to lowercase.\n\n'ucase'\nChange lowercase letters to uppercase.\n\nThe 'lcase' and 'ucase' conversions are mutually exclusive.\n\n'sparse'\nTry to seek rather than write NUL output blocks.  On a file\nsystem that supports sparse files, this will create sparse\noutput when extending the output file.  Be careful when using\nthis conversion in conjunction with 'conv=notrunc' or\n'oflag=append'.  With 'conv=notrunc', existing data in the\noutput file corresponding to NUL blocks from the input, will\nbe untouched.  With 'oflag=append' the seeks performed will be\nineffective.  Similarly, when the output is a device rather\nthan a file, NUL input blocks are not copied, and therefore\nthis conversion is most useful with virtual or pre zeroed\ndevices.\n\nThe 'sparse' conversion is a GNU extension to POSIX.\n\n'swab'\nSwap every pair of input bytes.\n\n'sync'\nPad every input block to size of 'ibs' with trailing zero\nbytes.  When used with 'block' or 'unblock', pad with spaces\ninstead of zero bytes.\n\nThe following \"conversions\" are really file flags and don't affect\ninternal processing:\n\n'excl'\nFail if the output file already exists; 'dd' must create the\noutput file itself.\n\n'nocreat'\nDo not create the output file; the output file must already\nexist.\n\nThe 'excl' and 'nocreat' conversions are mutually exclusive,\nand are GNU extensions to POSIX.\n\n'notrunc'\nDo not truncate the output file.\n\n'noerror'\nContinue after read errors.\n\n'fdatasync'\nSynchronize output data just before finishing, even if there\nwere write errors.  This forces a physical write of output\ndata, so that even if power is lost the output data will be\npreserved.  If neither this nor 'fsync' are specified, output\nis treated as usual with file systems, i.e., output data and\nmetadata may be cached in primary memory for some time before\nthe operating system physically writes it, and thus output\ndata and metadata may be lost if power is lost.  *Note sync\ninvocation::.  This conversion is a GNU extension to POSIX.\n\n'fsync'\nSynchronize output data and metadata just before finishing,\neven if there were write errors.  This acts like 'fdatasync'\nexcept it also preserves output metadata, such as the\nlast-modified time of the output file; for this reason it may\nbe a bit slower than 'fdatasync' although the performance\ndifference is typically insignificant for 'dd'.  This\nconversion is a GNU extension to POSIX.\n\n'iflag=FLAG[,FLAG]...'\nAccess the input file using the flags specified by the FLAG\nargument(s).  (No spaces around any comma(s).)\n\n'oflag=FLAG[,FLAG]...'\nAccess the output file using the flags specified by the FLAG\nargument(s).  (No spaces around any comma(s).)\n\nHere are the flags.\n\n'append'\nWrite in append mode, so that even if some other process is\nwriting to this file, every 'dd' write will append to the\ncurrent contents of the file.  This flag makes sense only for\noutput.  If you combine this flag with the 'of=FILE' operand,\nyou should also specify 'conv=notrunc' unless you want the\noutput file to be truncated before being appended to.\n\n'cio'\nUse concurrent I/O mode for data.  This mode performs direct\nI/O and drops the POSIX requirement to serialize all I/O to\nthe same file.  A file cannot be opened in CIO mode and with a\nstandard open at the same time.\n\n'direct'\nUse direct I/O for data, avoiding the buffer cache.  Note that\nthe kernel may impose restrictions on read or write buffer\nsizes.  For example, with an ext4 destination file system and\na Linux-based kernel, using 'oflag=direct' will cause writes\nto fail with 'EINVAL' if the output buffer size is not a\nmultiple of 512.\n\n'directory'\n\nFail unless the file is a directory.  Most operating systems\ndo not allow I/O to a directory, so this flag has limited\nutility.\n\n'dsync'\nUse synchronized I/O for data.  For the output file, this\nforces a physical write of output data on each write.  For the\ninput file, this flag can matter when reading from a remote\nfile that has been written to synchronously by some other\nprocess.  Metadata (e.g., last-access and last-modified time)\nis not necessarily synchronized.\n\n'sync'\nUse synchronized I/O for both data and metadata.\n\n'nocache'\nRequest to discard the system data cache for a file.  When\ncount=0 all cached data for the file is specified, otherwise\nthe cache is dropped for the processed portion of the file.\nAlso when count=0, failure to discard the cache is diagnosed\nand reflected in the exit status.\n\nNote data that is not already persisted to storage will not be\ndiscarded from cache, so note the use of the 'sync'\nconversions in the examples below, which are used to maximize\nthe effectiveness of the 'nocache' flag.\n\nHere are some usage examples:\n\n# Advise to drop cache for whole file\ndd if=ifile iflag=nocache count=0\n\n# Ensure drop cache for the whole file\ndd of=ofile oflag=nocache conv=notrunc,fdatasync count=0\n\n# Advise to drop cache for part of file\n# Note the kernel will only consider complete and\n# already persisted pages.\ndd if=ifile iflag=nocache skip=10 count=10 of=/dev/null\n\n# Stream data using just the read-ahead cache.\n# See also the 'direct' flag.\ndd if=ifile of=ofile iflag=nocache oflag=nocache,sync\n\n'nonblock'\nUse non-blocking I/O.\n\n'noatime'\nDo not update the file's access timestamp.  *Note File\ntimestamps::.  Some older file systems silently ignore this\nflag, so it is a good idea to test it on your files before\nrelying on it.\n\n'noctty'\nDo not assign the file to be a controlling terminal for 'dd'.\nThis has no effect when the file is not a terminal.  On many\nhosts (e.g., GNU/Linux hosts), this flag has no effect at all.\n\n'nofollow'\nDo not follow symbolic links.\n\n'nolinks'\nFail if the file has multiple hard links.\n\n'binary'\nUse binary I/O.  This flag has an effect only on nonstandard\nplatforms that distinguish binary from text I/O.\n\n'text'\nUse text I/O.  Like 'binary', this flag has no effect on\nstandard platforms.\n\n'fullblock'\nAccumulate full blocks from input.  The 'read' system call may\nreturn early if a full block is not available.  When that\nhappens, continue calling 'read' to fill the remainder of the\nblock.  This flag can be used only with 'iflag'.  This flag is\nuseful with pipes for example as they may return short reads.\nIn that case, this flag is needed to ensure that a 'count='\nargument is interpreted as a block count rather than a count\nof read operations.\n\nThese flags are all GNU extensions to POSIX. They are not supported\non all systems, and 'dd' rejects attempts to use them when they are\nnot supported.  When reading from standard input or writing to\nstandard output, the 'nofollow' and 'noctty' flags should not be\nspecified, and the other flags (e.g., 'nonblock') can affect how\nother processes behave with the affected file descriptors, even\nafter 'dd' exits.\n\nThe behavior of 'dd' is unspecified if operands other than 'conv=',\n'iflag=', 'oflag=', and 'status=' are specified more than once.\n\nThe numeric-valued strings above (N and BYTES) are unsigned decimal\nintegers that can be followed by a multiplier: 'b'=512, 'c'=1, 'w'=2,\n'xM'=M, or any of the standard block size suffixes like 'k'=1024 (*note"
                }
            ]
        },
        "Block size::).  These multipliers are GNU extensions to POSIX, except": {
            "content": "that POSIX allows BYTES to be followed by 'k', 'b', and 'xM'.  Note 'xM'\ncan be used more than once in a number.  Block sizes (i.e., specified by\nBYTES strings) must be nonzero.\n\nAny block size you specify via 'bs=', 'ibs=', 'obs=', 'cbs=' should\nnot be too large - values larger than a few megabytes are generally\nwasteful or (as in the gigabyte..exabyte case) downright\ncounterproductive or error-inducing.\n\nTo process data with offset or size that is not a multiple of the I/O\nblock size, you can use a numeric string N that ends in the letter 'B'.",
            "subsections": []
        },
        "For example, the following shell commands copy data in 1 MiB blocks": {
            "content": "between a flash drive and a tape, but do not save or restore a 512-byte\narea at the start of the flash drive:\n\nflash=/dev/sda\ntape=/dev/st0\n\n# Copy all but the initial 512 bytes from flash to tape.\ndd if=$flash iseek=512B bs=1MiB of=$tape\n\n# Copy from tape back to flash, leaving initial 512 bytes alone.\ndd if=$tape bs=1MiB of=$flash oseek=512B\n\nFor failing storage devices, other tools come with a great variety of\nextra functionality to ease the saving of as much data as possible\nbefore the device finally dies, e.g.  GNU 'ddrescue'\n(https://www.gnu.org/software/ddrescue/).  However, in some cases such a\ntool is not available or the administrator feels more comfortable with\nthe handling of 'dd'.  As a simple rescue method, call 'dd' as shown in\nthe following example: the operand 'conv=noerror,sync' is used to\ncontinue after read errors and to pad out bad reads with NULs, while\n'iflag=fullblock' caters for short reads (which traditionally never\noccur on flash or similar devices):\n\n# Rescue data from an (unmounted!) partition of a failing device.\ndd conv=noerror,sync iflag=fullblock </dev/sda1 > /mnt/rescue.img\n\nSending an 'INFO' signal (or 'USR1' signal where that is unavailable)\nto a running 'dd' process makes it print I/O statistics to standard\nerror and then resume copying.  In the example below, 'dd' is run in the\nbackground to copy 5GB of data.  The 'kill' command makes it output\nintermediate I/O statistics, and when 'dd' completes normally or is\nkilled by the 'SIGINT' signal, it outputs the final statistics.\n\n# Ignore the signal so we never inadvertently terminate the dd child.\n# Note this is not needed when SIGINFO is available.\ntrap '' USR1\n\n# Run dd with the fullblock iflag to avoid short reads\n# which can be triggered by reception of signals.\ndd iflag=fullblock if=/dev/zero of=/dev/null count=5000000 bs=1000 & pid=$!\n\n# Output stats every second.\nwhile kill -s USR1 $pid 2>/dev/null; do sleep 1; done\n\nThe above script will output in the following format:\n\n3441325+0 records in\n3441325+0 records out\n3441325000 bytes (3.4 GB, 3.2 GiB) copied, 1.00036 s, 3.4 GB/s\n5000000+0 records in\n5000000+0 records out\n5000000000 bytes (5.0 GB, 4.7 GiB) copied, 1.44433 s, 3.5 GB/s\n\nThe 'status=progress' operand periodically updates the last line of\nthe transfer statistics above.\n\nOn systems lacking the 'INFO' signal 'dd' responds to the 'USR1'\nsignal instead, unless the 'POSIXLYCORRECT' environment variable is\nset.\n\nAn exit status of zero indicates success, and a nonzero value\nindicates failure.\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}