cpio
Quick Reference
Command Name:
cpio
Category:
file archiving
Platform:
Linux/Unix
Basic Usage:
Common Use Cases
- 1
File archiving
Create archives of files and directories with metadata preserved
- 2
System backups
Backup system files while preserving permissions and ownership
- 3
Data recovery
Extract files from archives during system recovery operations
- 4
System installation
Package files for system installation processes like initramfs
Syntax
cpio {-o|--create} [-0acvABLV] [-C bytes] [-H format] [-M message] [-O [[user@]host:]archive] [-F [[user@]host:]archive] [--file=[[user@]host:]archive] [--format=format] [--message=message] [--null] [--reset-access-time] [--verbose] [--dot] [--append] [--block-size=blocks] [--dereference] [--io-size=bytes] [--quiet] [--force-local] [--rsh-command=command] [--help] [--version] < name-list [> archive] cpio {-i|--extract} [-bcdfmnrtsuvBSV] [-C bytes] [-E file] [-H format] [-M message] [-R [user][:.][group]] [-I [[user@]host:]archive] [-F [[user@]host:]archive] [--file=[[user@]host:]archive] [--make-directories] [--nonmatching] [--preserve-modification-time] [--numeric-uid-gid] [--rename] [--list] [--swap-bytes] [--swap] [--dot] [--unconditional] [--verbose] [--block-size=blocks] [--swap-halfwords] [--io-size=bytes] [--pattern-file=file] [--format=format] [--owner=[user][:.][group]] [--no-preserve-owner] [--message=message] [--force-local] [--no-absolute-filenames] [--sparse] [--only-verify-crc] [--quiet] [--rsh-command=command] [--help] [--version] [pattern...] [< archive] cpio {-p|--pass-through} [-0adlmuvLV] [-R [user][:.][group]] [--null] [--reset-access-time] [--make-directories] [--link] [--preserve-modification-time] [--unconditional] [--verbose] [--dot] [--dereference] [--owner=[user][:.][group]] [--no-preserve-owner] [--sparse] [--help] [--version] destination-directory < name-list
Options
Option | Description |
---|---|
-i, --extract |
Extract files from an archive |
-o, --create |
Create an archive |
-p, --pass-through |
Copy files from one directory to another |
-t, --list |
Print a table of contents of the input |
-v, --verbose |
Verbosely list the files processed |
-m, --preserve-modification-time |
Retain previous file modification times when creating files |
-d, --make-directories |
Create leading directories where needed |
-H, --format=FORMAT |
Use the specified archive format (bin, odc, newc, crc) |
-0, --null |
Filenames in the list are terminated by null characters instead of newlines |
-a, --reset-access-time |
Reset access times of files after reading them |
-u, --unconditional |
Replace all files unconditionally |
-F, --file=ARCHIVE |
Use the specified file as the archive instead of stdin or stdout |
-R, --owner=[USER][:.][GROUP] |
Set the ownership of all files created to the specified USER and/or GROUP |
Examples
How to Use These Examples
The examples below show common ways to use the cpio
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
# Create a cpio archive find . -name "*.txt" | cpio -ov > archive.cpio
Advanced Examples:
# Copy directory structure (pass-through mode) find source_dir -type d | cpio -pdmv destination_dir/