dd

Convert and copy a file, write disk headers, boot records, create a boot floppy. dd can makes 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 [Options]
	 
Key
   if=FILE
      Input file : Read from FILE instead of standard input.

   of=FILE
      Output file : Write to FILE instead of standard output.  Unless `conv=notrunc'
      is given, `dd' truncates FILE to zero bytes (or the size specified
      with `seek=').

   ibs=BYTES
      Read BYTES bytes at a time.

   obs=BYTES
      Write BYTES bytes at a time.

   bs=BYTES
      Block size, both read and write BYTES bytes at a time.  This overrides `ibs'
      and `obs'.

   cbs=BYTES
      Convert BYTES bytes at a time.

   skip=BLOCKS
      Skip BLOCKS `ibs'-byte blocks in the input file before copying.

   seek=BLOCKS
      Skip BLOCKS `obs'-byte blocks in the output file before copying.

   count=BLOCKS
      Copy BLOCKS `ibs'-byte blocks from the input file, instead of
      everything until the end of the file.

   conv=CONVERSION[,CONVERSION]...
      Convert the file as specified by the CONVERSION argument(s).  
      (No spaces around any comma)

     Conversions:
    `ascii'    Convert EBCDIC to ASCII.
    `ebcdic'   Convert ASCII to EBCDIC.
    `ibm'      Convert ASCII to alternate EBCDIC.
    `block'    For each line in the input, output `cbs' bytes, replacing the
               input newline with a space and padding with spaces as
               necessary.
    `unblock'  Replace trailing spaces in each `cbs'-sized input block with a newline.
    `lcase'    Change uppercase letters to lowercase.
    `ucase'    Change lowercase letters to uppercase.
    `swab'     Swap every pair of input bytes.  GNU `dd', unlike others,
               works when an odd number of bytes are read--the last byte is
               simply copied (since there is nothing to swap it with).
    `noerror'  Continue after read errors.
    `notrunc'  Do not truncate the output file.
    `sync'     Pad every input block to size of `ibs' with trailing zero bytes.
          

The numeric-valued options (BYTES and BLOCKS) can be followed by a multiplier: `b'=512, `c'=1, `w'=2, `xM'=M, or any of the standard block size suffixes like `k'=1024.

Examples:

Clone one hard drive onto another
$ dd if=/dev/sda of=/dev/sdb

Clone a hard drive to an image file
$ dd if=/dev/hda of=/image.img

Clone a hard drive to a zipped image file in 100Mb blocks
$ dd if=/dev/hda bs=100M | gzip -c > /image.img

Create a boot floppy:
$ dd if=boot.img of=/dev/fd0 bs=1440

"Success isn't something you chase. It's something you have to put forth the effort for constantly. Then maybe it'll come when you least expect it. Most people don't understand that" - Michael Jordan

Related:
CodeCoffee.com - dd examples
cp - Copy one or more files to another location
ddrescue - Data recovery tool
install - Copy files and set attributes
mtools - Manipulate MS-DOS files
sum - Print a checksum for a file
Equivalent Windows command: FSUTIL file setzerodata



Back to the Top

Simon Sheppard
SS64.com