Linux and Unix dd command

Quick links

About dd
Syntax
Examples
Related commands
Linux and Unix main page

About dd

Convert and copy a file.

Syntax

dd [OPERAND]...
dd OPTION

bs=BYTESforce ibs=BYTES and obs=BYTES
cbs=BYTESconvert BYTES bytes at a time
conv=CONVSconvert the file as per the comma separated symbol list
count=BLOCKScopy only BLOCKS input blocks
ibs=BYTESread BYTES bytes at a time
if=FILEread from FILE instead of stdin
iflag=FLAGSread as per the comma separated symbol list
obs=BYTESwrite BYTES bytes at a time
of=FILEwrite to FILE instead of stdout
oflag=FLAGSwrite as per the comma separated symbol list
seek=BLOCKSskip BLOCKS obs-sized blocks at start of output
skip=BLOCKSskip BLOCKS ibs-sized blocks at start of input
status=noxfersuppress transfer statistics

BLOCKS and BYTES may be followed by the following multiplicative suffixes: xM M, c 1, w 2, b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024,
and so on for T, P, E, Z, Y.

Each CONV symbol may be:

ascii from EBCDIC to ASCII
ebcdicfrom ASCII to EBCDIC
ibm from ASCII to alternate EBCDIC
blockpad newline-terminated records with spaces to cbs-size
unblockreplace trailing spaces in cbs-size records with newline
lcasechange upper case to lower case
nocreatdo not create the output file
excl fail if the output file already exists
notruncdo not truncate the output file
ucasechange lower case to upper case
swabswap every pair of input bytes
noerrorcontinue after read errors
syncpad every input block with NULs to ibs-size; when used with block or unblock, pad with spaces rather than NULs fdatasync physically write output file data before finishing fsync likewise, but also write metadata

Each FLAG symbol may be:

appendappend mode (makes sense only for output)
direct use direct I/O for data
dsyncuse synchronized I/O for data
synclikewise, but also for metadata
fullblockaccumulate full blocks of input (iflag only)
nonblockuse non-blocking I/O
nofollowdo not follow symlinks
nocttydo not assign controlling terminal from file

Sending a USR1 signal to a running 'dd' process makes it print I/O statistics to standard error and then resume copying.

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid

18335302+0 records in 18335302+0 records out 9387674624 bytes (9.4 GB) copied, 34.6279 seconds, 271 MB/s

Examples

Caution: Use dd cautiously, improperly entering the wrong values could inadvertently wipe, destroy, or overwrite the data on the hard disk drive.

dd if=/dev/sr0 of=/home/hope/exampleCD.iso bs=2048 conv=noerror,sync

Create a ISO disc image from the CD in the computer.

dd if=/dev/sda of=~/disk1.img

Create an img file of the /dev/sda hard disk drive. To restore that image type: dd if=disk1.img of=/dev/sda

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

Copy the contents from the if= drive /dev/sda to the of= drive /dev/sdb.

Related commands

cp
fdisk