Copy file archives in and out (UNIX)
Read/list an archive:
cpio -i[Bcdfmrtuv] [pattern...]
Write an archive:
cpio -o[Bacv]
Copy files:
cpio -p[adlmuv] directory
The cpio utility produces and reads files in the format specified by the POSIX cpio Archive/Interchange File Format. It operates in three modes.
The -i mode (copy in) extracts files from the standard input, which is assumed to be the product of a previous cpio -o. Only files with names that match patterns are selected. Multiple patterns may be specified. If no patterns are specified, the default for patterns is to select all files. The extracted files are conditionally created and copied into the current directory, and possibly any levels below, based on the options used. The permissions of the files will be those stored by the previous cpio -o invocation. The owner and group of the files will be that of the current user unless the user has appropriate privileges, which causes cpio to retain the owner and group of the files stored by the previous cpio -o invocation.
The -o mode writes the archive to the standard output.
The -p mode (pass) reads the standard input to obtain a list of pathnames of files that are conditionally created and copied into the destination directory based upon the options used.
If an error is detected, the cause is reported and the cpio utility will continue to copy other files. The utility will skip over any unrecognized files encountered in the archive.
The following restrictions apply to the cpio utility:
Copy out the files listed by the ls utility and redirect them to the file archive:
ls | cpio -o >archive
Use the output file archive from the cpio -o utility, extract those files that match the patterns memo/al and memo/b*, create the directories below the current directory, and place the files in the appropriate directories:
cpio -id "memo/al" "memo/b*" <archive
Take the filenames piped to cpio from the find utility and copy or link those files to another directory named newdir, while retaining the modification time:
find . -depth -print | cpio -pdlmv newdir
When cpio restores a directory, it matches the permissions of the directory created to those of the original. If that directory lacks write permission, any attempt to copy additional files under that directory will fail. To get around this, save the files under a directory first before the directory itself. If find is used to generate pathnames for cpio, the -depth option should be supplied to find.
Note also that the controlling terminal (/dev/tty) is used to prompt the user for information when the -i or -r options are specified.