[Previous] [Contents] [Index] [Next]

cpio

Copy file archives in and out (UNIX)

Syntax:

Read/list an archive:

cpio -i[Bcdfmrtuv] [pattern...]

Write an archive:

cpio -o[Bacv]

Copy files:

cpio -p[adlmruv] directory

Options:

-a
Reset access times of input files after they've been copied. When the -l option is also specified, the access times of linked files aren't reset. You can use this option only with the -o or -i options.
-B
Cause input/output to be blocked 5120 bytes to the record. You can use this option only with the -o or -i options for data directed to or from character special files.
-c
Write header information in ASCII (Default; option present for compatibility)
-d
Create directories as needed. You can use this option only with the -i or -p options.
-f
Copy in all files except those in patterns. You can use this option only with the -i option.
-i
Copy in. (Extract files from an archive being read from standard input.)
-l
("el") Whenever possible, link files rather than copy them. You can use this option only with the -p option.
-m
Retain previous modification times. This option won't work on directories that are being copied. You can use this option only with the -i or -p options.
-o
Copy out. (Write an archive to standard output.)
-p
Pass. Conditionally copy files from a list read from standard input to the destination directory named as an argument to cpio.
-r
Interactively rename files. A new name for each file is requested from the user. Read and write permissions for the controlling terminal (/dev/tty) are required for this option. If you type a null line, the file is skipped. You should use this option only with the -i or -o options.
-t
Print a table of contents of the input. No files are created. You can use this option only with the -i option.
-u
Copy files unconditionally. Usually an older file doesn't replace a new file with the same name. You can use this option only with the -i or -p options.
-v
Be verbose. Print the names of the affected files. You can use this option only with the -i option. It provides a detailed listing when used with the -t option.
pattern
Simple regular expression given in the name-generating notation of the shell.
directory
The destination directory.

Description:

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 are those stored by the previous cpio -o invocation. The owner and group of the files are 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 continues to copy other files. The utility skips over any unrecognized files encountered in the archive.

The following restrictions apply to the cpio utility:

Examples:

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

Exit status:

0
All input files were copied.
2
The utility encountered errors in copying or accessing files or directories. An error is reported for nonexistent files or directories or for permissions that don't allow the user to access the source or target files.

Caveats:

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 fails. 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.

See also:

cp, find, pax, tar

Backing Up and Recovering Data in the Neutrino User's Guide


[Previous] [Contents] [Index] [Next]