User:LN2/Sandbox/dd

dd is a common UNIX program whose primary purpose is the low-level copying and conversion of raw data. The title of the UNIX sixth edition manual page of May 1975 was dd - convert and copy a file, and some have suggested that since "cc" was already in use as the code for the C Compiler, "dd" was used instead; in any case, DD is an acronym for "data definition" in IBM JCL (to which the command's syntax bears a strong resemblance) and the name and syntax of the command is generally presumed to be a bit of gallows humor.

is used to copy a specified number of bytes or blocks, performing on-the-fly byte order conversions, as well as more esoteric EBCDIC to ASCII conversions. is commonly used to copy regions of raw device files, e.g. backing up the boot sector of a hard disk, or to read fixed amounts of data from special files like  or. It also works well reading and writing to block based media like magnetic tape. Because dd with Unix can copy entire partitions or disks, it is used in computer forensics when the contents need to be preserved as a byte-exact copy. Using  would not be enough, since data from deleted files that may still be present on a disk are not visible through the file system interface. It is jokingly said to stand for "destroy disk" or "delete data", since, being used for low-level operations on hard disks, a small mistake, such as reversing the if and of parameters, may accidentally render the entire disk unusable.

The command line syntax of dd is unlike that of any other UNIX program; a violation of the Unix philosophy of using a common syntax for all command line tools. Generally, dd uses an  format, whereas most Unix programs use a   format. Also, dd's input is specified using the "if" (input file) option, while most programs simply take the name by itself. It is rumored to have been based on IBM's JCL, and though the syntax may have been a joke, there seems never to have been any effort to write a more Unix-like replacement. The obscure syntax may also have been deliberately designed to prevent careless usage, due to the major damage this utility can cause if misused (see anti-examples).

Usage
dd [options]

operands

 * if=file : Input File: Read from file instead from standard input.
 * of=file : Output File: Write to file instead to standard output. See also the keyword notrunc.
 * ibs=bytes : Input Block Size: Read bytes bytes at once.
 * obs=bytes : Output Block Size: Write bytes bytes at once.
 * bs=bytes : Block Size: A shortcut for ibs=bytes obs=bytes. If the user does not provide a block size, 512 bytes is used.  One can determine the block size of a storage medium by assuming a block size, writing one block and checking for an error message. One author wrote in 2005 that for "most modern drives", the optimum value for this operand for maximum read/write performance is 4k (i.e. bs=4k); however, the value of 1024 is far more widely used in practice.
 * count=blocks : Count: copy only this many blocks from the input to the output, then stop.
 * skip=blocks : When starting to read from input, skip blocks number of blocks of size ibs.
 * seek=blocks : When starting to write to output, skip blocks number of blocks of size obs.
 * conv=keywords : Convert the file according to a comma-separated list of keywords.
 * cbs=bytes : Convert Block Size: Convert bytes bytes at once.

conv
When specifying conv as parameter the following keywords may be used:


 * ascii : Convert from EBCDIC to ASCII.
 * ebcdic : Convert from ASCII to EBCDIC.
 * IBM : Convert from ASCII to an alternative EBCDIC.
 * block : Fill datasets which are terminated by a newline-character with space-characters to fit size of cbs.
 * unblock : Replace trailing space-characters in datasets of size cbs with newline-characters.
 * lcase : Change uppercase characters to lowercase.
 * ucase : Change lowercase characters to uppercase.
 * notrunc : Do not truncate output file to zero bytes before writing to it. If the existing output file is longer than the amount of data to be written to it, this will cause the written data to overwrite the initial portion, leaving the remainder intact.
 * swab : Swap every pair of input bytes.
 * noerror : Ignore reading errors and continue.
 * sync : Pad every input block with null bytes if it is shorter than the size specified. If used with block or unblock, pad with space characters instead.

Notes and units
On various systems the option --version is supported. dd will then output its version number and quit.

file may be any real file or any block-device file.

On certain systems bytes may be specified with multiplicative units. This units may then be:


 * c : Character: 1
 * w : Word: 2
 * b : Block: 512
 * kB : Decimal kilobytes: 1,000 bytes
 * k : Binary kilobytes (kibibytes): 1,024 bytes
 * MB : Decimal megabytes: 1,000,000 bytes
 * M : Binary megabytes (mebibytes): 1,048,576 bytes (1,024×1,024)

This may be carried on similarly with G, T, P, E, Z, Y. The standard "IEEE Std 1003.1" only requires that the 'b' and 'k' multipliers be supported, and does not specify the meaning of any other multipliers. Also, multiple numbers may be provided separated by 'x'. These numbers are multiplied together.

Examples
Note: Read the man page for your dd command before trying examples as your system may be different. These examples are for Linux: on other platforms the device names may be different and have different semantics. You must still adjust the commands to your platform. Make sure the if (source) and of (target) is specified correctly, or you may lose data.


 * To create an ISO image file named image.iso of a CD. Insert the source CD and unmount it first if auto CD mount is enabled, this is to improve performance by preventing random access to the mounted filesystem.




 * To create an image file named floppy.img of a floppy disk:




 * To copy the image file back to a floppy:




 * To create a file of the size 1 GB with the name reallylargefile, filled with random data:




 * As above but faster and cryptographicly less secure




 * As above but faster by increasing block size:




 * To create a file of the size 10 GB with the name virtualpartition, filled with zeros, and make it available as a ext2 virtual partition:


 * (reply yes when it says it's not a block device)
 * (reply yes when it says it's not a block device)


 * To create a 10GB sparse file which doesn't allocate any actual space (if the filesystem supports this feature):




 * To copy the first partition of the first hard disk to the file partitionone.




 * To copy the first IDE-harddisk (master) to the second IDE-hard disk (slave), i.e. clone the drive including file systems, partition tables and the master boot record.



For many more examples of the Linux dd command, which is the same as the UNIX version, go here: http://www.linuxquestions.org/questions/showthread.php?t=362506

Under Windows (GNU Unix Utils)
dd is available with the GNU Unix Utils.

Windows devices are named like \\.\PhysicalDrive0 or \\.\CDROM0.

To turn a CD into an ISO image:

Under Windows (Cygwin)
dd is also available within Cygwin (www.cygwin.com)

The CD-Rom is typically available as /dev/scd0 (first SCSI-device).

To turn a CD into an ISO image do



To turn a 3½" floppy into an image file do

Mount the floppy

Create the image

Unmount the floppy



Anti-examples
The following examples are provided to warn about the dangers of dd, if used incorrectly. Trying any of these commands with the proper privileges will almost certainly result in major data loss, and may make the system unusable. In order to prevent accidental copying and pasting, "dd" has been replaced with "[dd]" here.

This overwrites the complete first hard disk with null bytes, erasing it (though not in a manner that is as secure as overwriting with random data):



This overwrites the first few blocks of the first hard disk with the file, resulting in a loss of the partition table:



This will completely corrupt an entire hard disk (/dev/dsp is the sound player/recorder):



This will overwrite an entire disk with pseudorandom data, making its initial contents relatively irrecoverable



The examples above presume device names (valid on some Linux systems) that may be different on other platforms. Here are some common variations.

Mac OS X:



Minix:



NetBSD/OpenBSD (does not work if securelevel > 1):