dd command is used in Unix and Linux systems for low-level file copy. Since everything in a Unix-like system is a file, this makes dd particularly useful for copying disks and specific blocks of data from large files.
Common system administration tasks with dd
- copy or rewrite boot block on a disk
- securely erase boot block, section of a disk or whole disk/partition
- write ISO onto USB stick
- byte-for-byte copy of a disk or disk partition
- confirm a disk throughput (MB/sec capability for read/write)
Basic dd command syntax
Most commonly, you're running the dd with the following parameters:
- if – input file (or device)
- of – output file (or device)
- bs – block size (number of bytes or kilobytes/megabytes if you specify it like 128k or 1m)
- count – number of blocks that you want to copy (if nothing specified, dd will copy the whole file or disk)
So dd command line looks like this:
dd if=<SOURCE FILE> of=<DESTINATION FILE> bs=<BLOCKSIZE> count=<NUMBER OF BLOCKS>
Writing a disk image onto USB stick in MacOS
$ sudo dd if=./centos.dmg of=/dev/disk9 bs=1m 4311+1 records in 4311+1 records out 4520542208 bytes transferred in 1486.155206 secs (3041770 bytes/sec)
Disk speed with dd in Linux
Another really quick and easy way of using dd command is to indicate the disk throughput.
This example creates a 1GB file using direct I/O, thus reporting an accurate enough I/O capability of the disk under your current filesystem. 423MB/s is a sure enough sign that we are looking at an SSD and not HDD:
greys@s5:~ $ dd if=/dev/zero of=./test bs=512k count=256 oflag=direct 256+0 records in 256+0 records out 134217728 bytes (134 MB) copied, 0.317509 s, 423 MB/s
Know any more cool uses of dd command? Please let me know!