NAME [Toc] [Back]
cpio - copy file archives in and out; duplicate directory trees
SYNOPSIS [Toc] [Back]
cpio -o [-e extarg] [achvxABC]
cpio -i[bcdfmrstuvxBPRSU6] [pattern...]
cpio -p [-e extarg] [adlmruvxU] directory
DESCRIPTION [Toc] [Back]
The cpio command saves and restores archives of files on magnetic
tape, other devices, or a regular file, and copies files from one
directory to another while replicating the directory tree structure.
When cpio completes processing the files, it reports the number of
cpio -o (copy out, export) Read standard input to obtain a list
of path names, and copy those files to standard output
together with path name and status information. The
output is padded to a 512-byte boundary.
cpio -i (copy in, import) Extract files from standard input,
which is assumed to be the result of a previous cpio -o.
If pattern..., is specified, only the files with names
that match a pattern according to the rules of Pattern
Matching Notation (see regexp(5)) are selected. A leading
! on a pattern indicates that only those names that do
not match the remainder of the pattern should be selected.
Multiple patterns can be specified. The patterns are
additive. If no pattern is specified, the default is *
(select all files). See the f option, as well.
Extracted files are conditionally created and copied into
the current directory tree, as determined by the options
described below. The permissions of the files match the
permissions of the original files when the archive was
created by cpio -o unless the U option is used. File
owner and group are that of the current user unless the
user has appropriate privileges, in which case cpio
retains the owner and group of the files of the previous
cpio -p (pass through) Read standard input to obtain a list of
path names of files which are then conditionally created
and copied into the destination directory tree as
determined by the options described below. directory must
exist. Destination path names are interpreted relative to
Hewlett-Packard Company - 1 - HP-UX 11i Version 2: August 2003
With the -p option, when handling a link, only the link is
passed and no data blocks are actually read or written.
This is especially noteworthy with cpio -pl, where it is
very possible that all the files are created as links,
such that no blocks are written and "0 blocks" is reported
by cpio. (See below for a description of the -l option.)
Options [Toc] [Back]
cpio recognizes the following options, which can be appended as
appropriate to -i, -o, and -p. White space and hyphens are not
permitted between these options and -i, -o, or -p.
a Reset access times of input files after they are
b Swap both bytes and half-words. Use only with -i. See
the P option for details; see also the s and S options.
c Write or read header information in ASCII character
form for portability.
d Create directories as needed.
-e extarg Specifies the handling of any extent attributes of the
file(s) to be archived or copied. extarg takes one of
the following values.
warn Archive or copy the file and issue a warning
message if extent attributes cannot be
ignore Do not issue a warning message even if extent
attributes cannot be preserved.
force Any file(s) with extent attributes will not
be archived and a warning message will be
When using the -o option, extent attributes are not
preserved in the archive. Furthermore, the -p option
will not preserve extent attributes if the files are
being copied to a file system that does not support
extent attributes. If -e is not specified, the default
value for extarg is warn.
f Copy in all files except those selected by pattern....
h Follow symbolic links as though they were normal files
or directories. Normally, cpio archives the link.
Hewlett-Packard Company - 2 - HP-UX 11i Version 2: August 2003
l Whenever possible, link files rather than copying them.
This option does not destroy existing files. Use only
m Retain previous file modification time. This option
does not affect directories that are being copied.
r Rename files interactively. If the user types a null
line, the file is skipped.
s Swap all bytes of the file. Use only with -i. See the
P option for details; see also the s and S options.
t Print only a table of contents of the input. No files
are created, read, or copied.
u Copy unconditionally (normally, an older file does not
replace a newer file with the same name).
v Print a list of file names as they are processed. When
used with the t option, the table of contents has the
numeric-mode owner-name blocks date-time filename
where numeric-mode is the file privileges in numeric
format, owner-name is the name of the file owner,
blocks is the size of the file in 512-byte blocks,
date-time is the date and time the file was last
modified, and filename is the path name of the file as
recorded in the archive.
x Save or restore device special files. Since mknod() is
used to recreate these files on a restore, -ix and -px
can be used only by users with appropriate privileges
(see mknod(2)). This option is intended for
intrasystem (backup) use only. Restoring device files
from previous versions of the OS, or from different
systems can be very dangerous. cpio may prevent the
restoration of certain device files from the archive.
A Suppress warning messages regarding optional access
control list entries. cpio does not back up optional
access control list entries in a file's access control
list (see acl(5)). Normally, a warning message is
printed for each file that has optional access control
B Block input/output at 5120 bytes to the record (does
not apply to cpio -p). This option is meaningful only
with data directed to or from devices that support
Hewlett-Packard Company - 3 - HP-UX 11i Version 2: August 2003
variable-length records such as magnetic tape.
C Have cpio checkpoint itself at the start of each
volume. If cpio is writing to a streaming tape drive
with immediate-report mode enabled and a write error
occurs, it normally aborts and exits with return code
2. With this option specified, cpio instead
automatically restarts itself from the checkpoint and
rewrites the current volume. Alternatively, if cpio is
not writing to such a device and a write error occurs,
cpio normally continues with the next volume. With
this option specified, however, the user can choose to
either ignore the error or rewrite the current volume.
P Read a file written on a PDP-11 or VAX system (with
byte-swapping) that did not use the c option. Use only
with -i. Files copied in this mode are not changed.
Non-ASCII files are likely to need further processing
to be readable. This processing often requires
knowledge of file contents, and thus cannot always be
done by this program. The b, s, and S options can be
used when swapping all the bytes on the tape (rather
than just in the headers) is appropriate. In general,
text is best processed with P and binary data with one
of the other options.
R Resynchronize automatically when cpio goes "out of
phase", (see the DIAGNOSTICS section).
S Swap all half-words in the file. Use only with -i.
See the P option for details; see also the b and s
U Use the process's file-mode creation mask (see
umask(2)) to modify the mode of files created, in the
same manner as creat(2).
6 Process a UNIX Sixth-Edition-format file. Use only
Note that cpio archives created using a raw device file must be read
using a raw device file.
When the end of the tape is reached, cpio prompts the user for a new
special file and continues.
If you want to pass one or more metacharacters to cpio without the
shell expanding them, be sure to precede each of them with a backslash
Hewlett-Packard Company - 4 - HP-UX 11i Version 2: August 2003
Device files written with the -ox option (such as /dev/tty03) do not
transport to other implementations of HP-UX.
EXTERNAL INFLUENCES [Toc] [Back]
LC_COLLATE determines the collating sequence used in evaluating
pattern matching notation for file name generation.
LC_CTYPE determines the interpretation of text as single and/or
multi-byte characters, and the characters matched by character class
expressions in pattern matching notation.
LC_TIME determines the format and content of date and time strings
output when listing the contents of an archive with the v option.
LANG determines the language in which messages are displayed.
If LC_COLLATE, LC_CTYPE, or LC_TIME is not specified in the
environment or is set to the empty string, the value of LANG is used
as a default for each unspecified or empty variable. If LANG is not
specified or is set to the empty string, a default of "C" (see
lang(5)) is used instead of LANG. If any internationalization
variable contains an invalid setting, cpio behaves as if all
internationalization variables are set to "C". See environ(5).
International Code Set Support [Toc] [Back]
Single- and multibyte character code sets are supported.
RETURN VALUE [Toc] [Back]
cpio returns the following exit codes:
0 Successful completion. Review standard error for files that
could not be transferred.
1 Error during resynchronization. Some files may not have
2 Out-of-phase error. A file header is corrupt or in the
DIAGNOSTICS [Toc] [Back]
Out of phase--get help
Perhaps the "c" option should[n't] be used
cpio -i could not read the header of an archived file. The
header is corrupt or it was written in a different format.
Without the R option, cpio returns an exit code of 2.
If no file name has been displayed yet, the problem may be the
format. Try specifying a different header format option: null
for standard format; c for ASCII; b, s, P, or S, for one of the
Hewlett-Packard Company - 5 - HP-UX 11i Version 2: August 2003
byte-swapping formats; or 6 for UNIX Sixth Edition.
Otherwise, a header may be corrupt. Use the R option to have
cpio attempt to resynchronize the file automatically.
Resynchronizing means that cpio tries to find the next good
header in the archive file and continues processing from there.
If cpio tries to resynchronize from being out of phase, it
returns an exit code of 1.
Other diagnostic messages are self-explanatory.
EXAMPLES [Toc] [Back]
Copy the contents of a directory into a tape archive:
ls | cpio -o > /dev/rmt/c0t0d0BEST
Duplicate a directory hierarchy:
find . -depth -print | cpio -pd newdir
The trivial case
find . -depth -print | cpio -oB >/dev/rmt/c0t0d0BEST
can be handled more efficiently by:
find . -cpio /dev/rmt/c0t0d0BEST
WARNINGS [Toc] [Back]
Because of industry standards and interoperability goals, cpio does
not support the archival of files larger than 2 GB or files that have
user/group IDs greater than 60 K. Files with user/group IDs greater
than 60 K are archived and restored under the user/group ID of the
Do not redirect the output of cpio to a named cpio archive file
residing in the same directory as the original files belonging to that
cpio archive. This can cause loss of data.
cpio strips any leading ./ characters in the list of file names piped
Path names are restricted to PATH_MAX characters (see <limits.h> and
limits(5)). If there are too many unique linked files, the program
runs out of memory to keep track of them. Thereafter, linking
information is lost. Only users with appropriate privileges can copy
cpio tapes written on HP machines with the -ox[c] options can
sometimes mislead (non-HP) versions of cpio that do not support the x
Hewlett-Packard Company - 6 - HP-UX 11i Version 2: August 2003
option. If a non-HP (or non-AT&T) version of cpio happens to be
modified so that the (HP) cpio recognizes it as a device special file,
a spurious device file might be created.
If /dev/tty is not accessible, cpio issues a complaint and exits.
The -pd option does not create the directory typed on the command
The -idr option does not make empty directories.
The -plu option does not link files to existing files.
POSIX defines a file named TRAILER!!! as an end-of-archive marker.
Consequently, if a file of that name is contained in a group of files
being written by cpio -o, the file is interpreted as end-of-archive,
and no remaining files are copied. The recommended practice is to
avoid naming files anything that resembles an end-of-archive file
To create a POSIX-conforming cpio archive, the c option must be used.
To read a POSIX-conforming cpio archive, the c option must be used and
the b, s, S, and 6 options should not be used. If the user does not
have appropriate privileges, the U option must also be used to get
POSIX-conforming behavior when reading an archive. Users with
appropriate privileges should not use this option to get POSIXconforming
DEPENDENCIES [Toc] [Back]
If the path given to cpio contains a symbolic link as the last
element, this link is traversed and path name resolution continues.
cpio uses the symbolic link's target, rather than that of the link.
SEE ALSO [Toc] [Back]
ar(1), find(1), tar(1), cpio(4), acl(5), environ(5), lang(5),
STANDARDS CONFORMANCE [Toc] [Back]
cpio: SVID2, SVID3, XPG2, XPG3
Hewlett-Packard Company - 7 - HP-UX 11i Version 2: August 2003 [ Back ]