dd

Data Duplicator, convert and copy a file, write disk headers, boot records, create a boot floppy. dd can make an exact clone of an (unmounted) disk, this will include all blank space so the output destination must be at least as large as the input.

Syntax
      dd [operands ...]

operands

     bs=n     Set both input and output block size to n bytes, superseding the
              ibs and obs operands.  If no conversion values other than
              noerror, notrunc or sync are specified, then each input block is
              copied to the output as a single block without any aggregation
              of short blocks.

     cbs=n    Set the conversion record size to n bytes.  The conversion
              record size is required by the record oriented conversion values.

     conv=CONV[,CONV ...]
              Convert the file as per the comma separated symbol list, see CONVs.

     count=n  Copy only n input blocks.

     ibs=n    Set the input block size to n bytes instead of the default 512.

     if=file  Read input from file instead of the standard input.

     iflag=flag[,flag...]            
              See FLAGs

     iseek=n  Seek on the input file n blocks. This is synonymous with skip=n.

     obs=n    Set the output block size to n bytes instead of the default 512.

     of=file  Write output to file instead of the standard output.  Any regular
              output file is truncated unless the notrunc conversion value
              is specified.  If an initial portion of the output file is
              seeked past (see the oseek operand), the output file is truncated
              at that point.

     oflag=flag[,flag...]
              See FLAGs
     oseek=n  Seek on the output file n blocks.
              This is synonymous with  seek=n.

     seek=n   Seek n blocks from the beginning of the output before copying. On non-tape devices,
              an lseek(2) operation is used.  Otherwise, existing blocks are read and the
              data discarded.  If the user does not have read permission for the tape, it is positioned
              using the tape ioctl(2) function calls.  If the seek operation is past the end of file,
              space from the current end of file to the specified offset is filled with blocks of NUL bytes.

     skip=n   Skip n blocks from the beginning of the input before copying. On input which supports seeks,
              an lseek(2) operation is used. Otherwise, input data is read and discarded.  For pipes, the
              correct number of bytes is read.  For all other devices, the correct number of blocks is
              read without distinguishing between a partial or complete block being read.

     status=value
              Where value is one of the following:

              noxfer    Do not print the transfer statistics as the last line of status output.

              none      Do not print the status output.
                        Error messages are shown; informational messages are not.

              progress  Print basic transfer statistics once per second.

Each FLAG symbol may be:

              append   append mode (makes sense only for output; conv=notrunc suggested).

              direct  use direct I/O for data.

              directory fail unless a directory.

              dsync   use synchronized I/O for data.

              sync    Use synchronized I/O for data, but also for metadata.

              direct  Set F_NOCACHE on the output file to make writes bypass any local caching.

              fullblock  Accumulate full blocks of input (iflag only).

              nonblock  use non-blocking I/O.

              noatime  do not update access time.

              nocache  Request to drop cache. See also oflag=sync

              noctty   Do not assign controlling terminal from file.

              nofollow  Do not follow symlinks.
   

Each CONV symbol may be:

              ascii    From EBCDIC to ASCII.

              ebcdic   From ASCII to EBCDIC.

              excl     Fail if the output file already exists.

              ibm      From ASCII to alternate EBCDIC.

              block    Pad newline-terminated records with spaces to cbs-size.

              unblock  Replace trailing spaces in cbs-size records with newline.

              lcase    Change upper case to lower case.

              ucase    Change lower case to upper case.

              nocreat  Do not create the output file.

              notrunc  Do not truncate the output file.

              noerror  Continue after read errors.

              fdatasync  Physically write output file data before finishing.

              fsync    Physically write output file data before finishing, but also write metadata.

              sparse   Try to seek rather than write all-NUL output blocks.

              swab     Swap every pair of input bytes.

              sync     Pad every input block with NULs to ibs-size; when used with block or unblock,
                       pad with spaces rather than NULs.

The numeric-valued options (N and BYTES) may be followed by the following multiplicative suffixes: c=1, w=2, b=512, kB=1000, K=1024, MB=1000*1000, M=1024*1024, xM=M, GB=1000*1000*1000, G=1024*1024*1024, and so on for T, P, E, Z, Y, R, Q.
Binary prefixes can be used, too: KiB=K, MiB=M, and so on. If N ends in 'B', it counts bytes not blocks.

When finished, dd displays the number of complete and partial input and output blocks, truncated input records and odd-length byte-swapping blocks to the standard error output. A partial input block is one where less than the input block size was read. A partial output block is one where less than the output block size was written. Partial output blocks to tape devices are considered fatal errors. Otherwise, the rest of the block will be written. Partial output blocks to character devices will produce a warning message. A truncated input block is one where a variable length record oriented conversion value was specified and the input line was too long to fit in the conversion record or was not newline ter- minated.

Normally, data resulting from input or conversion or both are aggregated into output blocks of the specified size. After the end of input is reached, any remaining output is written as a block. This means that the final output block might be shorter than the output block size.

The name dd is thought to be an allusion to the DD statement found in IBM’s Job Control Language (JCL), where the acronym stands for "Data Description". The lack of any confirmation prompt before truncating the output file has popularised the jocular name 'Data Destroyer'.

If dd receives a SIGINFO signal, the current input and output block counts will be written to the standard error output in the same format as the standard completion message. If dd receives a SIGINT signal, the current input and output block counts will be written to the standard error output in the same format as the standard completion message and dd will exit.

dd can copy a smaller drive to a larger one, but can’t copy a larger drive to a smaller one.

When cloning a disk drive, its a good idea to list the partitions before and afterwards using sudo fdisk –l
An empty/unformatted drive will appear as "Disk dev/sdn doesn’t contain a vaild partition table".

Exit Status

The dd utility exits 0 on success, and >0 if an error occurs.

Examples

Clone the drive sda onto drive sdb:

$ dd if=/dev/sda of=/dev/sdb

Clone the drive hda onto an image file:

$ dd if=/dev/hda of=/image.img

Copy a CD or DVD disc to a .iso image file, first unmounting the disc:

sudo umount /dev/dvd-device

dd if=/dev/dvd-device of=dvd.iso bs=2048 conv=sync,notrunc
# dvd-device will typically be dvd for a dvd disc or cdrom for a cdrom disc.

Clone a hard drive to a zipped image file in 100Mb blocks:

$ dd if=/dev/hda bs=100M | gzip -c > /image.img

Create a 10 KB file filled with random data (10 x 1K blocks):

$ dd if=/dev/random of=random.bin bs=1024 count=10

Create an 8 GB empty file (also known as "sparse file") called spacer.img:

$ dd if=/dev/zero of=spacer.img bs=1 count=0 seek=8G

Completely wipe the hard drive hdz by overwriting it with random data:

$ dd if=/dev/urandom of=/dev/hdz

Create a boot floppy:

$ dd if=boot.img of=/dev/fd0 bs=1440

“All of my servers have an 8GB empty spacer.img file that does absolutely nothing except take up space. That way in a moment of full-disk crisis I can simply delete it and buy myself some critical time” ~ Brian Schrader

Related Linux commands

CodeCoffee.com - dd examples.
cp - Copy one or more files to another location.
cpio - Copy files to and from archives.
ddrescue - Data recovery tool.
install - Copy files and set attributes.
lsblk - List block devices.
mtools - Manipulate MS-DOS files.
sum - Print a checksum for a file.
tr - Translate, squeeze, and/or delete characters.
Equivalent Windows command: FSUTIL file setzerodata, or bbcopy


 
Copyright © 1999-2026 SS64.com
Some rights reserved