copy file archives in and out
cpio -o [ -aBLuvV ]
[ -C bufsize ]
[ -c | -H format ]
[ -K volumesize ]
[ [ -O file [, file ... ] ]
[ -M message ] ]
[ -Pifd,ofd ]
cpio -i [ -6AbBcdfkmnqrsStTuvV ]
[-C bufsize ]
[ [ -I file [, file ... ] ]
[ -M message ] ]
[ -Pifd,ofd ]
[ pattern ... ]
cpio -p [ -adlLmruvV ]
[ -Pifd,ofd ]
cpio copies files to and from an archive file or another
There are three main options to cpio which determine its
mode of operation. These modes are used to create an archive
(cpio -o), extract files from an archive (cpio
-i), and copy files from one filesystem to another (cpio
-p). There are a number of secondary options, which are
interpreted differently depending on which mode of operation
cpio is in.
(copy out) Reads a list of pathnames from the standard input, and
copies those files onto the standard output together with pathname
and status information. Output is padded to a 512-byte boundary by
(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 the wildcard patterns are selected. (See
for details of the notation used.) Extracted files are conditionally
created and copied into the current directory tree in accordance
with the secondary options described below.
If cpio is used to copy files by a process without
appropriate privileges, the access permissions are set in the same
would have set them when given the
mode argument, matching
the file permissions supplied by the
c_mode field of the
cpio format. The owner and group of the files will be that
of the current user unless the user is root, which causes
cpio to retain the owner and group of the files of the
previous cpio -o.
If cpio -i tries to create a file that already exists and
the existing file is the same age or newer, cpio will
output a warning message and not replace the file. (The
-u option can be used to unconditionally overwrite the
(pass) Reads the standard input to obtain a list of pathnames of
files that are conditionally created and copied into the destination
directory tree based upon the options described
below. Archives of text files created by cpio are portable
between implementations of UNIX System V.
The following additional options are recognized by
cpio. Their interpretation depends on the context selected
by the primary option (-o, -i, or -p):
Process a UNIX System Sixth Edition format file. Used only with the
Reset access times of input files after they have been
copied. Access times are not reset for linked files when cpio
-pla is specified.
Suppress absolute filenames. A leading ``/'' character is
removed from the filename during copy-in. If a pattern is provided,
it should match the relative (rather than the absolute) pathname.
Reverse the order of the bytes within each word. Use only with the
Block input/output 5,120 bytes to the record. The default buffer
size is 512 bytes when this and the -C options are not
used. (-B does not apply to the pass option;
-B is meaningful only with data directed to or from a
character-special device, for example, /dev/rdsk/f0q15dt.)
For portability, write header information in ASCII
character form. Always use this option when the origin and
destination machines are of different types.
Block input/output bufsize bytes to the record, where
bufsize is replaced by a positive integer. The default
buffer size is 512 bytes when this and -B options are not
used. (-C does not apply to the pass option;
-C is meaningful only with data directed to or from a
character-special device, for example, /dev/rmt/c0s0.)
When used with the -K option, bufsize is forced
to be a 1KB multiple.
Create directories as needed.
Copy in all files except those in patterns. (See the
paragraph on cpio -i for a description of
format may take any of the following values:
(binary format) This is a non-portable version of the -c
(new character format with checksum) Write checksum information in
the header of each file. This option uses the SVR4
extended ASCII header format.
(new character format without checksum) Write archives using the
SVR4 extended ASCII header format.
(old character format) This has the same functionality as
-I file[, file ... ]
Read the contents of file as input. If file is a
character-special device, when the first medium is full, replace the
medium and type a carriage return to continue to the next
medium. You can perform an unattended multi-archive restore if you
specify a comma-separated list of files.
Use only with the -i option.
Attempt to skip corrupted file headers and I/O errors that
may be encountered. If you want to copy files from a medium that is
corrupted or out of sequence, this option lets you read only those
files with good headers. (For cpio archives that contain
other cpio archives, if an error is encountered,
cpio may terminate prematurely. cpio will find
the next good header, which may be one for a smaller archive, and
terminate when the smaller archive's trailer is encountered.) Used
only with the -i option.
Specify the size of the media volume. Must be in 1KB
blocks. For example, a 1.2MB floppy disk has a
volumesize of 1200. Must include the -C option
with a bufsize multiple of 1KB.
If you specify an incorrect size with -K, the command
executes without error, but cpio generates the message
``out of sync: bad magic'' when the volume is read.
(-K is not available with cpio -i.)
Note that this option is not needed with SCSI tape
Link files rather than copying them whenever possible. Used only
with the -p option.
Follow symbolic links.
This option requires that you use the -follow option to
when it is used in conjunction with cpio.
Retain previous file modification time. This option is ineffective
on directories that are being copied.
Define a message to use when switching media. When you use the
-O or -I options and specify a character-special
device, you can use this option to define the message that is
printed when you reach the end of the medium. One %d can
be placed in the message to print the sequence number of the next
medium needed to continue.
Calculate the checksum value for each file read from an archive (the
checksum value is equivalent to that produced by the command
sum -r). Filetypes other than regular files produce a
checksum of 0 (zero). This option is intended to be used in
conjunction with the -itv options; the first entry on each
output line is the checksum of an archived file.
-O file[, file ... ]
Direct the output of cpio to file. If
file is a character-special device, when the first medium
is full, replace the medium and type a carriage return to continue
to the next medium. You can change the end-of-media (EOM)
message using the -M option.
You can perform an unattended multi-archive backup if you specify a
comma-separated list of files. Unless you use
SCSI devices, you should specify the volume size using the
-K option. Note that cpio assumes that all
specified devices have the same volume size.
Use only with the -o option.
Use file descriptors ifd and ofd for input from
and output to a parent process. Any end-of-media (EOM)
message is written to ofd rather than to
/dev/tty. This option is only useful to programmers who
want to write applications that communicate with cpio
by a parent process. The file descriptors must be opened prior to,
and remain open on the invocation of cpio by the
Extract files quickly. cpio extracts only the specified
files from the archive and then stops. Shell regular expressions
(wildcards) cannot be used in the filenames to be extracted.
Rename files interactively. If the user types a null line, the file
is skipped. If the user types a ``.'', the original pathname
will be copied.
Swap bytes within each half word. Use only with the -i
Swap halfwords within each word. Use only with the -i
Truncate long filenames to 14 characters. Use only with the
Print a table of contents of the input. No files are created.
Copy unconditionally (normally, an older file will not replace a
newer file with the same name).
(verbose) Print a list of filenames. When used with the -t
option, the table of contents looks like the output of an ls
-l command (see
(special verbose) Print a dot for each file seen. This shows
cpio is working without printing filenames.
Absolute and relative pathnames
Files may be archived with relative or absolute pathnames. Absolute
pathnames specify the location of a file in relation to the root
directory (/); relative pathnames specify the location of
a file relative to the current working directory. As an example,
consider the following cpio commands, as executed from the
ls /u/bulls/eye | cpio -ocv > arcfile1
ls eye | cpio -ocv > arcfile2
The first command archives the file /u/bulls/eye,
including its absolute pathname, as arcfile1. The second
command archives eye as arcfile2, without
storing any information about the path.
If you restore from arcfile1, eye will be
written back to the directory /u/bulls no matter what your
working directory. Restoring from arcfile2 will write
eye to your current directory. In either case, you are not
allowed to restore the file to a directory if you do not have write
permission on that directory.
When making a cpio archive, consider whether you will
always want to restore the files with absolute pathnames. You can
extract files archived with absolute pathnames into their original
directory, whatever your current working directory. If necessary,
you can specify the -A option to suppress the absolute
pathname, and extract files into a different path.
If you opt to archive files using relative pathnames, you will have
to change directory to the one where the archive was created in
order to extract the files with their original pathnames.
Handling multiple-volume archives
If cpio reaches end of medium (the end of a floppy disk,
for example) when writing to (-o) or reading from
(-i) a character-special device, and -O and
-I are not used, cpio will print the message:
If you want to go on, type device/filename when ready.
To continue, you must replace the medium and type the
character-special device name (for example,
/dev/rdsk/f0q15dt) and a carriage return. You may want to
continue by directing cpio to use a different device. For
example, if you have two floppy drives, you may want to switch
between them so cpio can proceed while you are changing
the floppies. (A carriage return alone causes the cpio
process to exit.)
The -I and -O options allow you to read and
write archives using multiple devices. This may be useful if you
wish to perform an unattended backup or restore and have several
archive devices available. If cpio runs out of devices it
will prompt you to replace the medium in the last device in the
list. It will repeat this action until the end of the archive.
Transferring files between different systems
cpio assumes 4-byte words. This is an important
consideration when writing a portable archive for transfer to UNIX
systems running on different hardware platforms. The byte order
within each word can be changed using the -s and
-S options; this may be necessary when transferring files
between systems running on big-endian and little-endian hosts.
You should also use one of the options -c, -H
crc, -H newc or -H odc when transferring
files between different systems. These options write the header
information in a portable ASCII character form.
The -H newc and -H crc options are suitable for
systems that understand the SVR4 extended-ASCII
cpio archive format.
cpio is capable of recognizing the cpio format
that was used to create an archive.
You can also use the
command to discover the format type used by a cpio
A pattern is a regular expression given in the
filename-generating notation of
Several patterns may be used to specify the filenames to be
extracted from a cpio archive when the -i flag
In patterns, metacharacters ?, ,
] also match the slash (/) character, and backslash (\)
is an escape character. A ``!'' metacharacter means
not. (For example, !abc* would exclude all files
that begin with abc.)
Multiple patterns may be specified. However, if no
pattern is given, the default pattern is
``'' (that is, select all files).
for more information about shell regular expressions.
Each pattern must be enclosed in double quotes to prevent
the shell from expanding it before it is passed to cpio.
cpio returns the following values:
an error occurred
The following examples show cpio being used to create,
verify and read archives, and to copy a complete directory
The first example demonstrates the creation of an archive, as a
file, or on a device such as a floppy drive. The filenames output by
the ls command are directed through a pipe to cpio
-o. These files are grouped and directed (>) to a single file
(../newfile). The -c option ensures that the
file will be portable to other machines. Instead of ls,
you could use find,
and so on, to pipe a list of names to cpio.
ls | cpio -ocv > ../newfile
The -v option is used to output a list of filenames as
they are extracted.
You can also direct the output to a device instead of a file (here
specifying a blocking factor using the -B option):
ls | cpio -ocvB -O /dev/rfd096ds15
These files are stored with pathnames relative to the current
directory. In this way, they can be extracted into any desired
If you use find with cpio, you can place
conditions on which files are to be archived. For example, you can
choose to archive:
It is important to use the -depth option of find
to generate pathnames for cpio. This eliminates problems
cpio could have trying to copy files from non-writable
Files of a given size (using the -size option of
Files which have had their contents accessed (-atime), or
modified (-mtime) in a given time period.
Files which have had details such as their ownership, type, number
of links, or file size changed in a given time period
Files with certain permissions, such as executable files
Files owned by certain users (-user) or groups
You should also use the -follow option of find
if you follow symbolic links using the -L option of
You can create a multivolume archive of the entire filesystem on
floppies using the -O option of cpio:
find / -depth -print | cpio -ovcBK 1200 -O /dev/rfd096ds15
This archive stores the files with absolute pathnames. When
extracted, they will be put in exactly the same places in the
directory structure. (If necessary, you can suppress the leading
/ of absolute pathnames, using the -A option, to
change them to relative ones.)
To archive using relative pathnames, change directory to the one to
be archived (for example /u), and specify a relative path
(.), instead of an absolute one (/u), to
find . -depth -print | cpio -ocvB -O /dev/rct0
To archive onto block devices
(divisions. partitions, or whole disks)
larger than 2GB, pipe cpio output
command using the conv=bmode option:
find . -depth -print | cpio -ovcC8192 | dd of=/dev/my_spare_division conv=bmode bs=8k
The -mount option of find limits the archive to
the mounted filesystem where the search starts. For example, you
might want to archive just those files on the filesystem
(/), omitting any in filesystems mounted below /
(depending on the way your system was installed, this may include
/usr or /u):
find . -depth -mount -print | cpio -ocvB -O /dev/rct0
To limit the archive to just those files modified within the last
seven days, use the -mtime option of find:
find . -depth -mount -mtime -7 -print | cpio -ocvB -O /dev/rct0
Extracting files from an archive
The next example uses cpio -i to reverse the action of
cpio -o, and extract files stored with relative pathnames
in an archive.
cat newfile | cpio -icvd "memo/a1" "info/b"
Files that match the patterns memo/a1 and
info/b are extracted from the archive file,
newfile. (If no patterns were given, all files from
newfile would be extracted.)
The -d option creates the directories, memo and
info, below the current directory if they are not already
present, and places the extracted files in the appropriate
directories. If an archive has been created using absolute
pathnames, the files to be read have to be specified with their
original pathnames. The files would then be extracted into the same
If the archive had been written to a tape drive, you might use:
cpio -icdv -I /dev/rct0 "memo/a1" "memo/b"
The -d option will cause cpio to create
directories as needed.
To read an archive from a block device larger than 2GB,
use the conv=bmode option of the
command to read the data and pipe its output to cpio:
dd if=/dev/my_spare_division conv=bmode bs=8k | cpio -ivcC8192
Verifying an archive
If you specify the -t option as well as -i, the
archive will be read but not extracted. This combination is used for
verifying the contents of an archive. When combined with option
-v, the output list of contents looks like that from the
command ls -l:
cpio -ivt -I /dev/rct0
If you want to verify the checksums of files in an archive, use the
-n option to display these:
cpio -invt -I /dev/rct0
Copying a directory structure
cpio used with the -p option takes the filenames
piped to it and copies or links (-l option) those files to
another directory (../newdir), keeping the modification
time of the copied files (-m option).
find . -depth -print | cpio -pdlmv ../newdir
Reading from and writing to several devices
The -O option allows you to specify a comma-separated list
of devices to allow you to perform multi-volume unattended backups
and restores. For example, to perform a backup onto two
SCSI tape drives:
find . -depth -print | cpio -ov -O /dev/rStp0,/dev/rStp1
This example restores files from a two-volume archive using two
SCSI tape drives:
cpio -iv -I /dev/rStp0,/dev/rStp1
Directories with versioning enabled
Using cpio to overwrite a directory with versioning
enabled will disable versioning. It must be re-enabled if desired.
Archives written with a character header using the -H crc
or -H newc options are not readable on systems that do not
recognize the SVR4 extended-ASCII cpio
archive format. The -c or -H odc options should
be used to write archives that are to be read by these systems.
The -c, -H bin and -H odc format only
allows 16-bit inode numbers. To backup files with 32-bit inode
numbers, cpio will generate its own inode/device
numbers. There is a possibility that cpio will run out of
inode/device numbers when archiving files using this format. If
this should happen, the -H newc or -H crc
formats should be used; these extended headers store all 32 bits of
a file's inode.
You may run out of inodes if you are trying to restore an archived
32-bit inode number filesystem on a 16-bit inode number filesystem.
When using the expanded ASCII format (-H newc or
-H crc options), the SVR4 version of
cpio defers archiving an inode's data until it sees the
last hard link to it or EOF. cpio then writes
the headers of the links seen previously with their filesizes set to
zero. It follows these with the inode data for the last link. When
restoring from an archive, the SVR4 cpio may
create a read-only directory before attempting to write file data in
that directory. This will be unsuccessful unless you are
root; using the -depth option to find
does not help in these circumstances.
The SCO version of cpio overcomes this problem
by writing the same file data for each hard link. When restoring
from an archive, it recreates the hard links so they reference a
single inode. If you use the SVR4 cpio to
restore from an SCO cpio archive, each link
points to a separate copy of the original inode.
is used on the root filesystem in conjunction with the
-mount option to the
mount points are not backed up.
This is because -mount skips mounted filesystems.
Unless these filesystems are unmounted,
the mount points are skipped as well.
When restoring the root filesystem,
you may need to recreate the mount points manually
before restoring the filesystems associated with them.
For example, after you restore the root filesystem,
you may need to create the /stand directory before
restoring your backup of the boot filesystem.
Pathnames are restricted to 1024 characters.
cpio interprets the list of filenames read from its
standard input literally; if a filename has prefixed or postfixed
whitespace, cpio assumes that this is part of the
Only root can copy special files.
Blocks are reported in 512-byte quantities.
If a file has 000 permissions, contains more than 0 characters of
data, and the user is not root, the file will not be saved
Irwin tape drives should not be used for multivolume cpio
backups because of the variation in the effective size of each
Open UNIX 8 compatibility notes
When running ACP on Open UNIX 8 and UnixWare 7 systems,
set OSRCMDS=on to use
the SCO OpenServer version of the <cpio> command.
This provides the expected behaviors
for SCO OpenServer applications.
The SCO OpenServer version of this command
is also provided on Open UNIX 8 systems under the OSP feature
Running SCO OpenServer Applications
topic in the Open UNIX 8 documentation set.
cpio is conformant with:
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992: note that this command is marked as to be
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003