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=4M | Block size. Too small and the copy crawls. |
| count=<n> | Copy only n blocks. |
| status=progress | Show progress (GNU). On macOS press Ctrl+T instead. |
| conv=fsync | Flush to the device before exiting, so the numbers mean something. |
| conv=notrunc | Write in place without truncating the output file. |
範例
lsblkAlways confirm the device name immediately before the next command.
sudo dd if=ubuntu.iso of=/dev/sdb bs=4M status=progress conv=fsyncWrite an installer image to a whole USB device (Linux).
diskutil unmountDisk /dev/disk4 && sudo dd if=ubuntu.iso of=/dev/rdisk4 bs=4mOn 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