Cpio Command
The cpio command is a powerful utility used in
Unix-like operating systems for creating and extracting archive
files. It's particularly useful for handling file archives, often
used in conjunction with other commands like find for
selecting files and tar for creating tape archives,
though cpio itself can create various archive formats.
Cpio Archive Creation
To create a cpio archive, you typically pipe the output
of another command (like ls or find) into
cpio with the --create (or
-o) option. This tells cpio to read a list
of filenames from standard input and write them into an archive.
# Create a cpio archive from the current directory's files:
ls | cpio --create --file=archive.cpio
# Create a cpio archive using find for more control:
find . -print | cpio --create --file=archive.cpio
Cpio Archive Extraction
Extracting a cpio archive is done using the
--extract (or -i) option. You pipe the
archive content into cpio or specify the archive file.
The --make-directories (or -d) option is
crucial for recreating the directory structure from the archive.
# Extract a cpio archive to the current directory:
cpio --extract --make-directories < archive.cpio
# Extract a cpio archive from standard input:
cat archive.cpio | cpio --extract --make-directories
Cpio Archive Listing
You can also list the contents of a cpio archive
without extracting them using the --list (or
-t) option. This is useful for inspecting the archive's
contents before performing an extraction.
# List the contents of a cpio archive:
cpio --list < archive.cpio
Key Cpio Options
--create(-o): Create an archive.-
--extract(-i): Extract files from an archive. -
--list(-t): List the contents of an archive. -
--file=FILE(-F FILE): Use FILE as the archive file. -
--make-directories(-d): Create leading directories as needed. --verbose(-v): Verbose output.
For more detailed information and advanced usage, refer to the
official cpio man page or documentation from sources
like
Linux man-pages.