cpio
壓縮與傳輸
用法
find <path> | cpio -o > <archive.cpio>這是個老式打包工具,要打進去哪些檔案由標準輸入送來的名單決定,所以餵它的通常是 find;`-o` 寫包、`-i` 解包、`-t` 看清單,initramfs 用的可攜格式是 `-H newc`,而別人給的包要加 `--no-absolute-filenames`,免得它往絕對路徑裡寫。
常用選項
| 選項 | 含義 |
|---|---|
| -o | Copy-out: build an archive from the names arriving on stdin. |
| -i | Copy-in: extract from an archive on stdin. |
| -d | Create directories as needed while extracting. |
| -m | Preserve modification times. |
| -t | List the contents instead of extracting. |
| -v | Print names as they are processed. |
| -H newc | The portable SVR4 format, and the one initramfs images use. |
| --no-absolute-filenames | Refuse to extract to absolute paths from an untrusted archive (GNU cpio only). |
範例
find . -depth -print | cpio -ov -H newc > backup.cpioArchive exactly the file list that find produced.
cpio -idmv < backup.cpioExtract, creating directories and keeping timestamps.
cpio -itv < backup.cpioList what is inside first.
打包和壓縮是兩件事:tar 打包,gzip 壓小,.tar.gz 是兩樣一起。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. cpio 是做什麼的?
這是個老式打包工具,要打進去哪些檔案由標準輸入送來的名單決定,所以餵它的通常是 find;`-o` 寫包、`-i` 解包、`-t` 看清單,initramfs 用的可攜格式是 `-H newc`,而別人給的包要加 `--no-absolute-filenames`,免得它往絕對路徑裡寫。
Q. 怎麼寫?
find <path> | cpio -o > <archive.cpio> —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 8 個,完整列表在 man cpio。這條命令屬於壓縮與傳輸。
相關命令
man 手冊: man cpio