Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

dd

Copy data block by block: make disk images, write ISO files to USB, create files of a fixed size, wipe or test disks.

Level
Everyday Linux
Group
Disks and file systems
Needs root
For changes
Package
coreutils

What it does

dd if=INPUT of=OUTPUT bs=SIZE count=N reads blocks from the input and writes them to the output. It works on files and on raw devices (whole disks), so it can copy or destroy anything — people call it "disk destroyer" for a reason. Always check of=.

Options are written as name=value, not with dashes.

How to write it

dd [OPERAND]...

Options 15

Most used

if=FILE
Read from this file or device (default stdin).
of=FILE
Write to this file or device (default stdout).
bs=BYTES
Block size for read and write (like 1M, 4M).
count=N
Copy only N blocks.
ibs=BYTES
Read block size.
obs=BYTES
Write block size.
cbs=BYTES
Conversion block size.
skip=N, iseek=N
Skip N input blocks.
seek=N, oseek=N
Skip N output blocks.
conv=LIST
Conversions: notrunc, noerror, sync, sparse, fsync, fdatasync, excl, nocreat, ucase, lcase …
iflag=LIST
Input flags: fullblock, direct, nocache, skip_bytes, count_bytes …
oflag=LIST
Output flags: direct, sync, dsync, append, nocache, seek_bytes …
status=LEVEL
none, noxfer or progress (show progress).
--help
Show help.
--version
Show the version.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1Create a file of 1 GiB with zeros

    dd if=/dev/zero of=/swapfile bs=1M count=1024

    Good for swap files (no holes).

  2. 2Write an ISO to a USB stick

    dd if=rhel-10.0-x86_64-dvd.iso of=/dev/sdc bs=4M status=progress oflag=sync

    /dev/sdc is the whole stick (no number). Check with lsblk first!

  3. 3Back up a partition to an image

    dd if=/dev/vdb1 of=/backup/vdb1.img bs=4M status=progress

    Unmount it first for a consistent copy.

  4. 4Back up the MBR (first 512 bytes)

    dd if=/dev/vda of=/root/mbr.bin bs=512 count=1

    Boot code and MBR table.

  5. 5Wipe the start of a disk

    dd if=/dev/zero of=/dev/vdb bs=1M count=10

    Removes partition table and signatures at the start (wipefs is cleaner).

  6. 6Test write speed

    dd if=/dev/zero of=/var/tmp/test bs=1M count=1024 oflag=direct status=progress

    direct skips the cache; delete the file after.

  7. 7Test read speed

    dd if=/var/tmp/test of=/dev/null bs=1M iflag=direct

    Real disk reads.

  8. 8A busy CPU process for labs

    dd if=/dev/zero of=/dev/null &

    Practice top, nice and kill.

  9. 9Random data file

    dd if=/dev/urandom of=random.bin bs=1M count=10

    Test files that do not compress.

  10. 10Copy a failing disk and go on after errors

    dd if=/dev/sdb of=/backup/sdb.img bs=64K conv=noerror,sync status=progress

    Bad blocks become zeros (ddrescue is better for this).

  11. 11Restore only the boot code

    dd if=/root/mbr.bin of=/dev/vda bs=446 count=1

    Restores only the boot code, not the partition table (446 bytes).

Watch out

  • of= on the wrong disk destroys it at once. There is no question and no undo.
  • Without status=progress dd prints nothing until it is done; send kill -USR1 PID for a status.

Exit codes

0 :: Done. 1 :: Error.