← 返回命令列表

Linux command

cpio 命令

文件

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Create

find . -depth | cpio -o > [archive.cpio]

Extract

cpio -i < [archive.cpio]

List

cpio -t < [archive.cpio]

Copy

find . | cpio -pd [/destination]

说明

cpio (copy in/out) is an archiving utility that reads file lists from stdin and creates or extracts archives. It's commonly used in initramfs images, RPM packages, and for copying directory trees. The tool operates in three modes: copy-out (create archives), copy-in (extract archives), and pass-through (copy files without archiving). Unlike tar, which accepts file arguments directly, cpio reads filenames from standard input, typically piped from find. This design provides greater flexibility for file selection using find's powerful filtering capabilities. cpio is the preferred format for Linux initial ramdisk images because of its simplicity and kernel support. RPM packages use cpio internally for storing files. The format supports various archive types and can preserve file metadata including permissions, ownership, and timestamps.

参数

-o, --create
Create archive (copy-out mode)
-i, --extract
Extract archive (copy-in mode)
-p, --pass-through
Copy files (pass-through mode)
-t, --list
List archive contents
-v, --verbose
Verbose mode
-d, --make-directories
Create directories as needed
-u, --unconditional
Overwrite files unconditionally
-m, --preserve-modification-time
Preserve modification times

FAQ

What is the cpio command used for?

cpio (copy in/out) is an archiving utility that reads file lists from stdin and creates or extracts archives. It's commonly used in initramfs images, RPM packages, and for copying directory trees. The tool operates in three modes: copy-out (create archives), copy-in (extract archives), and pass-through (copy files without archiving). Unlike tar, which accepts file arguments directly, cpio reads filenames from standard input, typically piped from find. This design provides greater flexibility for file selection using find's powerful filtering capabilities. cpio is the preferred format for Linux initial ramdisk images because of its simplicity and kernel support. RPM packages use cpio internally for storing files. The format supports various archive types and can preserve file metadata including permissions, ownership, and timestamps.

How do I run a basic cpio example?

Run `find . -depth | cpio -o > [archive.cpio]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --create do in cpio?

Create archive (copy-out mode)