CPIO(1)

πŸ‘‘ CPIO(1) πŸ‘‘

okay bestie, gather round, because this is the General Commands Manual page for cpio(1) and it is long β€” so long that it comes in parts. part one is right here, and it's giving "your whole file-copying life is about to change" energy. πŸ’…


✨ NAME ✨

cpio β€” copy files to and from archives πŸŽ€


✨ SYNOPSIS ✨

cpio -i [options] [pattern ...] [< archive]
cpio -o [options] < name-list [> archive]
cpio -p [options] dest-dir < name-list

✨ DESCRIPTION ✨

so like, cpio copies files back and forth between archives and directories. that's the whole vibe. πŸ¦‹

this particular implementation can extract from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images β€” and it can create tar, pax, cpio, ar, and shar archives. versatile queen πŸ‘‘

the first option you hand to cpio is the mode indicator, and it has to be one of these three icons:

  • -i β€” Input. reads an archive from standard input (unless you overrode that somewhere) and extracts the contents to disk, or β€” if you also passed -t β€” just lists the contents to standard output. and if you specified one or more file *pattern*s, only the files matching one of those patterns get extracted. picky, but in a good way.
  • -o β€” Output. reads a list of filenames from standard input and produces a brand new archive on standard output (again, unless overridden) containing the specified items.
  • -p β€” Pass-through. reads a list of filenames from standard input and copies those files to the specified directory.

✨ OPTIONS ✨

unless it specifically says otherwise, every option here works in all operating modes. so like, no mode-locking, bestie, options are for everyone πŸ’–

  • -0, --null β€” read filenames separated by NUL characters instead of newlines. this is necessary if any of the filenames being read might contain newlines. yes, filenames can contain newlines, no, we don't make the rules 😭
  • -6, --pwb β€” when reading a binary format archive, assume it's the earlier one, from the PWB variant of 6th Edition UNIX. when writing a cpio archive, use the PWB format. vintage!! πŸ•°οΈ
  • -7, --binary β€” (o mode only) when writing a cpio archive, use the (newer, non-PWB) binary format.
  • -A β€” (o mode only) append to the specified archive. not yet implemented, so don't get your hopes up, babe. πŸ™ˆ
  • -a β€” (o and p modes) reset access times on files after they are read.
  • -B β€” (o mode only) block output to records of 5120 bytes.
  • --b64encode β€” (o mode only) encode the archive with base64, after any compression. in input mode this option is ignored, because base64-encoded archives are recognized automatically on input. if you give both this and --uuencode, whichever one you specified last wins. last-one-standing rules 🫢
  • -C size β€” (o mode only) block output to records of size bytes.
  • -c β€” (o mode only) use the old POSIX portable character format. exactly equivalent to --format odc.
  • -d, --make-directories β€” (i and p modes) create directories as necessary. no more "no such file or directory" meltdowns πŸ’…
  • -E file β€” (i mode only) read the list of file name patterns from file to list and extract.
  • -F file, --file file β€” read archive from file or write archive to file.
  • -f pattern β€” (i mode only) ignore files that match pattern. not today, pattern. 🚫
  • -H format, --format format β€” (o mode only) produce the output archive in the specified format. supported formats include:
    • cpio β€” synonym for odc.
    • newc β€” the SVR4 portable cpio format.
    • odc β€” the old POSIX.1 portable octet-oriented cpio format.
    • pax β€” the POSIX.1 pax format, an extension of the ustar format.
    • ustar β€” the POSIX.1 tar format.

the default format is odc. see libarchive-formats(5) for more complete information about the formats currently supported by the underlying libarchive(3) library.

  • -h, --help β€” print usage information. the classic cry for help, but make it documentation ✨
  • -I file β€” read archive from file.
  • -i, --extract β€” Input mode. see above for description. (scroll up bestie, it's the -i bullet πŸ’–)
  • --insecure β€” (i and p mode only) disable security checks during extraction or copying. this allows extraction via symbolic links, absolute paths, and path names containing β€˜..’ in the name. genuinely do not do this unless you know exactly what you're doing β€” that's a big yikes. 😬
  • -J, --xz β€” (o mode only) compress the file with xz-compatible compression before writing it. in input mode this option is ignored; xz compression is recognized automatically on input.
  • -j β€” synonym for -y. (yes, just -y with extra steps, iconic)
  • -L, --dereference β€” (o and p modes) all symbolic links will be followed. normally, symbolic links are archived and copied as symbolic links; with this option, the target of the link gets archived or copied instead. follow your dreams (and your symlinks) πŸ¦‹
  • -l, --link β€” (p mode only) create links from the target directory to the original files, instead of copying. no duplicate data, we love an efficient queen πŸ‘‘
  • --grzip β€” (o mode only) compress the resulting archive with grzip(1). in input mode this option is ignored.
  • --lrzip β€” (o mode only) compress the resulting archive with lrzip(1). in input mode this option is ignored.
  • --lz4 β€” (o mode only) compress the archive with lz4-compatible compression before writing it. in input mode this option is ignored; lz4 compression is recognized automatically on input.
  • --zstd β€” (o mode only) compress the archive with zstd-compatible compression before writing it. in input mode this option is ignored; zstd compression is recognized automatically on input.
  • --lzma β€” (o mode only) compress the file with lzma-compatible compression before writing it. in input mode this option is ignored; lzma compression is recognized automatically on input.
  • --lzop β€” (o mode only) compress the resulting archive with lzop(1). in input mode this option is ignored.
  • --passphrase passphrase β€” the passphrase is used to extract or create an encrypted archive. currently, zip is the only format that cpio can handle encrypted archives with. you shouldn't use this option unless you realize how insecure use of this option is. like, fr fr, read that sentence twice. 😭
  • -m, --preserve-modification-time β€” (i and p modes) set file modification time on created files to match those in the source. timestamps stay iconic, unchanged, periodt.
  • -n, --numeric-uid-gid β€” (i mode, only with -t) display numeric uid and gid. by default, cpio displays the user and group names when they are provided in the archive, or looks up the user and group names in the system password database. numbers only, no name-dropping 😌
  • --no-preserve-owner β€” (i mode only) do not attempt to restore file ownership. this is the default when run by non-root users.
  • -O file β€” write archive to file.
  • -o, --create β€” Output mode. see above for description. πŸ“€
  • -p, --pass-through β€” Pass-through mode. see above for description. πŸ”
  • --preserve-owner β€” (i mode only) restore file ownership. this is the default when run by the root user.
  • --quiet β€” suppress unnecessary messages. shhh 🀫
  • -R [user][:][group], --owner [user][:][group] β€” set the owner and/or group on files in the output. here's the breakdown, because the punctuation matters:
    • if group is specified with no user (for example, -R :wheel) then the group will be set but not the user.
    • if the user is specified with a trailing colon and no group (for example, -R root:) then the group will be set to the user's default group.
    • if the user is specified with no trailing colon, then the user will be set but not the group.
    • in -i and -p modes, this option can only be used by the super-user.
    • (for compatibility, a period can be used in place of the colon.)
  • -r β€” (All modes.) rename files interactively. for each file, a prompt is written to /dev/tty containing the name of the file, and a line is read from /dev/tty. if the line read is blank, the file is skipped. if the line contains a single period, the file is processed normally. otherwise, the line is taken to be the new name of the file. you're the main character of this extraction ✨
  • -t, --list β€” (i mode only) list the contents of the archive to stdout; do not restore the contents to disk. window shopping only πŸ›οΈ
  • -u, --unconditional β€” (i and p modes) unconditionally overwrite existing files. ordinarily, an older file will not overwrite a newer file on disk. with this, all bets are off, no cap.
  • --uuencode β€” (o mode only) encode the archive with uuencode(1), after any compression. in input mode this option is ignored; uuencoded archives are recognized automatically on input. if both this option and --b64encode are given, the last one specified is used. 🫢
  • -V, --dot β€” print a dot to stderr for each file as it is processed. superseded by -v. cute but old news πŸ’…
  • -v, --verbose β€” print the name of each file to stderr as it is processed. with -t, provide a detailed listing of each file. tell me everything, bestie πŸ—£οΈ
  • --version β€” print the program version information and exit.
  • -y β€” (o mode only) compress the archive with bzip2-compatible compression before writing it. in input mode this option is ignored; bzip2 compression is recognized automatically on input.
  • -Z β€” (o mode only) compress the archive with compress-compatible compression before writing it. in input mode this option is ignored; compression is recognized automatically on input.
  • -z β€” (o mode only) compress the archive with gzip-compatible compression before writing it. in input mode this option is ignored; gzip compression is recognized automatically on input. the people's champion of compression πŸ’–

✨ EXIT STATUS ✨

the cpio utility exits 0 on success, and >0 if an error occurs. zero means slay, anything else means something went wrong. simple math. ✨


✨ ENVIRONMENT ✨

these environment variables affect the execution of cpio, so pay attention bestie:

  • LANG β€” the locale to use. see environ(7) for more information.
  • TZ β€” the timezone to use when displaying dates. see environ(7) for more information.

✨ EXAMPLES ✨

the cpio command is traditionally used to copy file hierarchies in conjunction with the find(1) command. so like, find finds, cpio copies, they're a duo, iykyk πŸ’œ

this first example simply copies all files from src to dest:

find src | cpio -pmud dest

by carefully selecting options to the find(1) command and combining it with other standard utilities, it is possible to exercise very fine control over which files are copied. this next example copies files from src to dest that are more than 2 days old and whose names match a particular pattern:

find src -mtime +2 | grep foo[bar] | cpio -pdmu dest

and this example copies files from src to dest that are more than 2 days old and which contain the word β€œfoobar”:

find src -mtime +2 | xargs grep -l foobar | cpio -pdmu dest

πŸ’– COMPATIBILITY πŸ’–

Okay so real talk, the mode options i, o, and p, plus the options a, B, c, d, f, l, m, r, t, u, and v, all play nice with SUSv2. Slay.

Now the history lesson nobody asked for but everyone needs: the old POSIX.1 standard was lowkey rigid. It said only -i, -o, and -p get to be actual command-line options, and each one took a single argument that was just a list of modifier characters. So like, the standard syntax lets you do -imu, but it does not support -miu or -i -m -u. Why? Because m and u are only modifiers to -i, bestie β€” they're not command-line options in their own right. They can't just be out here standing alone. πŸ’…

The syntax this implementation supports is backwards-compatible with the standard, which is iconic of it. But for best compatibility, scripts should limit themselves to the standard syntax. No cap. 🫢


🌈 SEE ALSO 🌈


πŸ‘‘ STANDARDS πŸ‘‘

There is no current POSIX standard for the cpio command, which is honestly giving abandoned-by-the-academy energy. It did show up in ISO/IEC 9945-1:1996 (β€œPOSIX.1”), but then got dropped from IEEE Std 1003.1-2001 (β€œPOSIX.1”). Not me getting ghosted by the standards committee. 😭

The cpio, ustar, and pax interchange file formats are defined by IEEE Std 1003.1-2001 (β€œPOSIX.1”) for the pax command, so at least the formats have a home. 🏠


πŸ¦‹ HISTORY πŸ¦‹

The original cpio and find utilities were written by Dick Haight while he was working in AT&T's Unix Support Group. They first appeared in 1977 in PWB/UNIX 1.0, the β€œProgrammer's Work Bench” system developed for use within AT&T. Then they were first released outside of AT&T as part of System III Unix in 1981.

And here's the gag: cpio actually predates tar, even though it was not well-known outside of AT&T until some time later. So the way that cpio was out here being the original main character while tar got all the fame? It's giving underrated legend. πŸ‘‘

This is a complete re-implementation based on the libarchive(3) library. ✨


πŸ’€ BUGS πŸ’€

The cpio archive format has several basic limitations, and we're gonna be honest about them because we're besties:

  • It does not store user and group names β€” only numbers. So as a result, it cannot be reliably used to transfer files between systems with dissimilar user and group numbering. Imagine the chaos. πŸ™ˆ
  • Older cpio formats limit the user and group numbers to 16 or 18 bits, which is insufficient for modern systems. Tiny little numbers, bestie, they simply cannot.
  • The cpio archive formats cannot support files over 4 gigabytes β€” except for the β€œodc” variant, which can support files up to 8 gigabytes. That's it, that's the ceiling. 🧱
Fr fr, keep these in mind before you trust a cpio archive with anything precious. It's not being dramatic, it's just the format.

And that's a wrap on CPIO(1), bestie!! πŸŽ€ This gorgeous little page came to you from the Debian folks, dated September 16, 2014, and it lives in the CPIO(1) section of the manual. Go archive something iconic. πŸ’–βœ¨πŸŒˆπŸ¦‹

πŸ“¦ where this page comes from