cpio.h - Linux
Overview
cpio is a command-line utility for creating, extracting, or manipulating compressed or uncompressed cpio archives. It’s commonly used to backup or transfer files between systems.
Syntax
cpio [-abcdfilmnopuvz] [-A archive] [-B blocksize] [files...]
Options/Flags
- -a: Append specified files to an existing archive.
- -b: Swap the bytes in each word for portability across architectures.
- -c: Create a new cpio archive.
- -d: Extract files from an archive.
- -f: Specify the archive file to operate on.
- -i: Read files from standard input to create an archive.
- -l: List the contents of an archive.
- -m: Preserve file modification timestamps.
- -n: Never create the archive even if it doesn’t exist.
- -o: Extract files to standard output.
- -p: Preserve file permissions.
- -u: Update existing files in the archive if they’re newer than their archive counterparts.
- -v: Print verbose information during operation.
- -z: Compress/decompress the archive using gzip.
Examples
Creating an archive:
cpio -cvf archive.cpio files...
Extracting an archive:
cpio -idvf archive.cpio
Updating an archive:
cpio -umv archive.cpio updated_files...
Common Issues
- Ensure that the archive file exists before trying to extract files.
- Use the
-v
option to troubleshoot extraction or creation issues. - If creating an archive with compression, ensure the required compression tool (
gzip
or others) is installed.
Integration
cpio can be integrated with other commands, such as:
-
tar: Convert cpio archives to tar archives:
cpio -iv archive.cpio | tar -xvf -
-
find: Create an archive of specific files:
find . -name '*.txt' -exec cpio -vo archive.cpio -- {} +
Related Commands
- tar: Archive and compress files.
- gzip: Compress files.
- bzip2: Compress files.
- 7z: Archive and compress files.