ruk·si

dd
Copy File-like Objects

Updated at 2018-06-28 23:18

dd is for convert-and-copy but cc was taken. dd is also one of the few standard Unix programs that have non-standard option passing style.

dd if=<INPUT_FILE> of=<OUTPUT_FILE>

# copying a DVD into a file
dd if=/dev/sr0 of=my-image.iso

# copying contents of a broken hard drive
dd vs=512 conv=noerror,sync if=/dev/sda of=/dev/sdb

dd can be used to create files of specific sizes for testing.

dd if=/dev/zero of=./60mb-file.dat bs=1M count=60
# 62914560 bytes (63 MB, 60 MiB) copied, 0.144701 s, 435 MB/s
sha1sum ./60mb-file.dat
# 233ba936226a3ac499e67babaebd0d4aafb9761a  ./60mb-file.dat

dd if=/dev/zero of=./1gb-file.dat bs=1G count=1
# 1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.595166 s, 1.8 GB/s
sha1sum ./1gb-file.dat
# 2a492f15396a6768bcbca016993f4b4c8b0b5307  ./1gb-file.dat

dd if=/dev/zero of=./2gb-file.dat bs=1G count=2
# 2147483648 bytes (2.1 GB, 2.0 GiB) copied, 1.04518 s, 2.1 GB/s
sha1sum ./2gb-file.dat
# 91d50642dd930e9542c39d36f0516d45f4e1af0d  ./2gb-file.dat