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