cpio(1) — Commands
OSF
NAME
cpio − Copies files to and from archive storage
SYNOPSIS
cpio −o[aBcv] [−C value] [−M "string"] [−Odevice]
cpio −i[bBcdfmrsStuv6] [−C value] [−M "string"] [−Idevice] [pattern ...]
cpio −p[adlmruv] directory
The cpio command copies files between archive storage and the file system.
FLAGS
A − (dash) is required before the −i, −I, −o, −O, and −p flags; all other flags follow −i, −o, or −p without leading spaces and without a dash.
The following two flags are preceded by a dash and must be used separately from the other flags.
−IdeviceSpecifies the input device containing the archive. This argument must be present to import data from a device.
−Odevice
Specifies the output device to store the archive. This argument must be present to export data to a device.
Not all of the following flags can be used with each of the −o, −i, and −p flags.
aResets the access times of copied files to the current time. (When the l flag is also specified, the access times of the linked files are not reset.)
bSwaps both bytes and halfwords. (See also the s and S flags.) (If there is an odd number of bytes or halfwords in the file being processed, data can be lost.) This flag can only be used with cpio −i.
BPerforms block input/output, 5120 bytes to a record. (Cannot be used with cpio −p; meaningful only with data directed to or from /dev/rmt/∗.) This flag does not work with certain magnetic tape drives. Note that the C and B flags are mutually exclusive. If you specify both, the last one on the command line is used.
cWrites header information in ASCII character form. Specify this flag when POSIX compliance is required and when you are creating or restoring archives for or from another system.
C valuePerforms block input/output using value as the record size. Note that the C and B flags are mutually exclusive. If you specify both, the last one on the command line is used.
dCreates directories as needed.
fCopies all files except those matching pattern (cpio −i only).
lLinks files rather than copying them, whenever possible. This flag can only be used with cpio −p.
mRetains previous file modification time. This flag cannot be used when copying directories.
MSpecifies the End-of-Media message. This flag is used to customize the message that appears when it is time to change archive volumes. −M is valid only when −I or −O is also specified.
rCauses cpio to ask you whether or not to rename each file before copying it. If you do not want to change the filename, enter the current filename or press <Return> only. In this last case, cpio does not copy the file.
sSwaps bytes. This flag can only be used with cpio −i. (If there is an odd number of bytes in the file being processed, data can be lost.)
SSwaps halfwords. This flag can only be used with cpio −i. (If there is an odd number of halfwords in the file being processed, data can be lost.)
tCreates a table of contents of the input. This does not copy any files.
uCopies unconditionally. Otherwise, a file from the archive with the same name as an existing file in the file system is copied only if the archived file is the newer one.
vLists filenames. If you use this with the t flag, the output looks similar to that of the ls −l command.
6Processes an old file (one written in UNIX Sixth Edition format). This flag can only be used with cpio −i.
DESCRIPTION
The cpio command is used to save and restore data from traditional format cpio archives.
cpio −o (copy out)
This command reads file pathnames from standard input and copies these files to standard output along with pathnames and status information. Output is padded to a 512-byte boundary.
cpio −i (copy in)
This command reads from standard input an archive file created by the cpio −o command and copies from it the files with names that match pattern. These files are copied into the current directory tree. Permissions of the files are the same as the permissions associated with the files copied out using cpio −o. The owner and group of the files are that of the current user unless the user is superuser, which causes cpio to retain the owner and group of the files of the previous cpio −o.
You can list more than one pattern using the filename notation described under the sh command. Note, however, that in this application the special characters ∗ (asterisk), ? (question mark), and [ ] (brackets) match the / (slash) in pathnames, in addition to their use as described in the sh command reference page. The default pattern is ∗, selecting all files in the archive. In an expression such as [a-z], the dash means "through" according to the current collating sequence. The collating sequence is determined by the LC_COLLATE environment variable. See the OSF/1 User’s Guide for more information on collating sequences.
cpio −p (directory copy)
This command reads file pathnames from standard input and copies these files into the named directory. The specified directory must already exist. If these pathnames include directory names and if these directories do not already exist, you must use the −d flag to cause the directories to be created.
Special files are not supported. Pathnames cannot exceed 128 bytes. Avoid giving cpio pathnames made up of many uniquely linked files because cpio might not have enough memory to keep track of them, and could lose linking information.
EXAMPLES
1.To copy files onto magnetic tape, enter:
cpio −ov <file_list −O/dev/rmt12
or
cpio −ov <file_list ...>/dev/rmt12
This copies the files with pathnames that are listed in the file specification in a compact form onto the magnetic tape (/dev/rmt12). The −v flag causes cpio to display the name of each file as it is copied. This command is useful for making backup copies of files.
2.To copy files in the current directory whose names end with .c onto magnetic tape, enter:
ls ∗.c | cpio −ov −O/dev/rmt12
or
ls ∗.c | cpio −ov >/dev/rmt12
3.To copy the current directory and all subdirectories onto magnetic tape, enter:
find . −print | cpio −ov −O/dev/rmt12
or
find . −print | cpio −ov >/dev/rmt12
This saves the directory tree that starts with the current directory (.) and includes all of its subdirectories and files. Another way to do this is by entering the following:
find . −cpio /dev/rmt12 −print
The −print flag displays the name of each file as it is copied.
4.To list the files that have been saved onto a magnetic tape with cpio, enter:
cpio −itv −I/dev/rmt12
or
cpio −itv </dev/rmt12
This displays the table of contents of the data previously saved onto /dev/rmt12 in cpio format. To list only the file pathnames, use only the −it flags.
5.To copy the files previously saved with cpio from a magnetic tape, enter:
cpio −idmv −I/dev/rmt12
or
cpio −idmv </dev/rmt12
This copies the files previously saved onto /dev/rmt12 by cpio back into the file system (specified by the −i flag). The −d flag allows cpio to create the appropriate directories if a directory tree was saved. The −m flag maintains the last modification time that was in effect when the files were saved. The −v causes cpio to display the name of each file as it is copied.
6.To copy selected files from magnetic tape, enter:
cpio −i −I/dev/rmt12 "∗.c" "∗.o"
or
cpio −i "∗.c" "∗.o" </dev/rmt12
This copies the files that end with .c or .o from magnetic tape. Note that the patterns ∗.c and ∗.o must be enclosed in " " (double quotes) to prevent the shell from treating the ∗ (asterisk) as a pattern-matching character. This is a special case in which cpio itself decodes the pattern-matching characters.
7.To rename files as they are copied from magnetic tape, enter:
cpio −ir −I/dev/rmt12
or
cpio −ir </dev/rmt12
The −r flag causes cpio to ask you whether or not to rename each file before copying it from magnetic tape. For example, the message:
Rename <prog.c>
asks whether to give the file saved as prog.c a new name as it is copied in. To rename the file, type the new name and press <Return>. To keep the same name, you must enter the name again. To avoid copying the file at all, press <Return> alone.
8.To copy a directory and all of its subdirectories, enter:
mkdir /u/jim/newdir
find . −print | cpio −pdl /u/jim/newdir
This duplicates the current directory tree, including the current directory and all of its subdirectories and files. The duplicate is placed in the new /u/jim/newdir directory. The −l flag causes cpio to link files instead of copying them, when possible.
CAUTIONS
When redirecting the output from cpio to a special file (device), redirect it to the raw device and not the block device. Because writing to a block device is done asynchronously, there is no way to know if the end of the device has been reached.
RELATED INFORMATION
Commands: ar(1), find(1), ls(1), sh(1), tar(1).
OSF/1 User’s Guide.