home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: cp Chapter 2
UNIX Commands
Next: Reference: crontab








Copy file archives in from or out to tape or disk, or to another location on the local machine. Each of the three flags -i , -o , or -p accepts different options.

cpio -i [ options ] [ patterns ]

Copy in (extract) files whose names match selected patterns . Each pattern can include filename metacharacters from the Bourne shell. (Patterns should be quoted or escaped so they are interpreted by cpio , not by the shell.) If no pattern is used, all files are copied in. During extraction, existing files are not overwritten by older versions in the archive (unless -u is specified).

cpio -o [ options ]

Copy out a list of files whose names are given on the standard input.

cpio -p [ options ] directory

Copy files to another directory on the same system. Destination pathnames are interpreted relative to the named directory .

Comparison of valid options

Options available to the -i , -o , and -p flags are shown respectively in the first, second, and third row below. (The - is omitted for clarity.)


: 6   b B c C d E f H I k   m M  r R s S t u v V


: a A   B c C       H     L   M O            v V


: a           d         l L m      R       u v V



Reset access times of input files.


Append files to an archive (must use with -O ).


Swap bytes and half-words. Words are 4 bytes.


Block input or output using 5120 bytes per record (default is 512 bytes per record).


Read or write header information as ASCII characters; useful when source and destination machines are of differing types.

-C n

Like B , but block size can be any positive integer n .


Create directories as needed.

-E file

Extract filenames listed in file from the archives.


Reverse the sense of copying; copy all files except those that match patterns .

-H format

Read or write header information according to format . Values for format are crc (ASCII header containing expanded device numbers), odc (ASCII header containing small device numbers), ustar (IEEE/P1003 Data Interchange Standard header), or tar (tar header).

-I file

Read file as an input archive.


Skip corrupted file headers and I/O errors.


Link files instead of copying.


Follow symbolic links.


Retain previous file modification time.

-M msg

Print msg when switching media. Use variable %d in the message as a numeric ID for the next medium. -M is valid only with -I or -O .

-O file

Direct the output to file .


Rename files interactively.


Reassign file ownership and group information to the user's login ID (privileged users only).


Swap bytes.


Swap half-words.


Print a table of contents of the input (create no files). When used with the -v option, resembles output of ls -l .


Unconditional copy; old files can overwrite new ones.


Print a list of filenames.


Print a dot for each file read or written (this shows cpio at work without cluttering the screen).


Process a UNIX 6th Edition archive format file.


Generate a list of old files using find ; use list as input to cpio :

find . -name "*.old" -print | cpio -ocBv\
    > /dev/rst8

Restore from a tape drive all files whose name contains "save" (subdirectories are created if needed):

cpio -icdv "save" < /dev/rst8

To move a directory tree:

find . -depth -print | cpio -padm /mydir

Previous: Reference: cp UNIX in a Nutshell: System V Edition Next: Reference: crontab
Reference: cp Book Index Reference: crontab

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System