dd

圧縮と転送

書き方

dd if=<source> of=<target> bs=4M status=progress

ブロックのまま丸ごと写すので、起動用のイメージを装置へ書き込むのはこれです。`of=` に書いた相手は確認もなく 0 番のブロックから上書きされ、戻す手立てはないため、Enter を押す直前に lsblk で装置名を確かめ、速さは `bs=4M`、進み具合は `status=progress`(macOS は Ctrl+T)で見ます。

よく使うオプション

オプション意味
if=<file>Input file or device. Leaving it out reads stdin.
of=<file>Output. Whatever this names is overwritten from block zero, with no confirmation.
bs=4MBlock size. Too small and the copy crawls.
count=<n>Copy only n blocks.
status=progressShow progress (GNU). On macOS press Ctrl+T instead.
conv=fsyncFlush to the device before exiting, so the numbers mean something.
conv=notruncWrite in place without truncating the output file.

lsblk

Always confirm the device name immediately before the next command.

sudo dd if=ubuntu.iso of=/dev/sdb bs=4M status=progress conv=fsync

Write an installer image to a whole USB device (Linux).

diskutil unmountDisk /dev/disk4 && sudo dd if=ubuntu.iso of=/dev/rdisk4 bs=4m

On macOS the disk must be unmounted first, or dd fails with Resource busy; rdiskN is the fast raw path.

まとめることと縮めることは別の仕事です。tar がまとめ、gzip が縮め、.tar.gz はその両方です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. dd は何をしますか。

ブロックのまま丸ごと写すので、起動用のイメージを装置へ書き込むのはこれです。`of=` に書いた相手は確認もなく 0 番のブロックから上書きされ、戻す手立てはないため、Enter を押す直前に lsblk で装置名を確かめ、速さは `bs=4M`、進み具合は `status=progress`(macOS は Ctrl+T)で見ます。

Q. どう打ちますか。

dd if=<source> of=<target> bs=4M status=progress — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man dd にあります。このコマンドは圧縮と転送の仲間です。

関連するコマンド

man ページ: man dd