The cpio command has three functions:
it copies one or more files into an archive file (Format 1)
it retrieves files from a previously created archive (Format 2)
it copies files into a directory (Format 3)
The cpio command has been withdrawn from the XG4 standard and replaced by the command pax.
Consequently, only the pax command should be used in the future, since cpio is now supported only for compatibility reasons.
Syntax
Format 1: | cpio -o[Bacv][ -D archive] |
Format 2: | cpio -i[Bcdmrtuvf][ -D archive][ pattern...] |
Format 3: | cpio -p[adlmruv] dir |
Only the three main options -o, -i and -p are detailed in the descriptions of the various Copy files out
Modifiers
Single option
(o - out) Copy files in
Modifiers
Single option
(in) cpio reads from standard input or the archive specified with the single option -D, which is assumed to be the product of a previous cpio -o, and extracts from it only those files with names that match pattern (see below). The extracted files are copied into the current directory tree in accordance with the specified options. The extracted files are given the same permissions as the files copied out with cpio -o. The user ID and group ID are those of the user calling cpio - i. It is only when the system administrator calls cpio - i that the extracted files retain the same user or group ID as the files copied out with cpio -o. Only the system administrator can extract special files.
pattern specifies the files to be selected from the archive. All shell metacharacters for file name generation can be used in defining pattern (see section “File name generation”). If pattern is not specified, all files are extracted from the archive. Copy files to a directory
Additional option
(p - pass) cpio reads a list of pathnames of plain files and copies these files to the named directory dir in accordance with the specified options. The number of 512-byte blocks copied by cpio is written to standard error.
Name of the directory to which the files are to be copied. This directory must exist even if the -d modifier is specified. Modifiers and single optionsThe following modifiers may be specified in any order. Apart from the single option -D, they must all be directly appended to the main option -o,-i or -p without intervening blanks.
|
Error
You have not specified the -c option. Due to compatibility reasons, cpio maintains the i-nodes of files to be copied in the old format, so i-nodes exceeding 64 Kbytes can only be processed if you have specified the -c option.
You did not specify the -d option in Format 2. |
Locale
The following environment variables affect the execution of cpio: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the internationalized environment for the behavior of ranges, equivalence classes and multicharacter collating elements in extended regular expressions for yes/no queries. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_CTYPE governs character classes, character conversion (shifting) and the behavior of character classes in regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
All files in the current directory with names that begin with mb are to be copied out to an archive file named mailarchive:
The find command searches the current directory for file names that begin with mb and writes all such file names to standard output, which is piped (|) to the standard input of cpio. cpio -o then reads the file names and copies the appropriate files along with status information to the archive file mailarchive (option -D). When it has finished, cpio writes the number of copied blocks to standard error. |
Example 2
List the contents of the archive file named mailarchive:
|
Example 3
The directory named dir.old is to be copied together with all its subdirectories. The duplicate directory is to be named dir.new:
The cd command changes the current directory to dir.old. The command find then searches this directory and all other directories below it and writes the names of all the files that it find to standard output. Since the standard output of find is piped (|) to the standard input of cpio, cpio reads the file names and copies the files to the directory dir.new (which, in this example, is at the same level in the file tree as dir.old). Subdirectories are created as needed (-d), i.e. all subdirectories of dir.old are copied recursively. Since the -l option also specified here, instead of copying the files, links are created to the files where possible. |
See also
ar, cat, echo, find, ls, pax, tar |