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


cpio

cpio control_options [options ]

Copy file archives in from, or out to, tape or disk, or to another location on the local machine. Each of the three control options, -i , -o , or -p accepts different options. (See also pax and tar .)

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 options are shown respectively in the first, second, and third row below. (The - is omitted for clarity.)

i

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

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

: a           d         l L m   P  R       u v V

Options

-a

Reset access times of input files.

-A

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

-b

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

-B

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

-c

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

-C n

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

-d

Create directories as needed.

-E file

Extract filenames listed in file from the archive.

-f

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 bar (bar format header and file, read-only, Solaris only), 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). Solaris also allows CRC , TAR , and USTAR .

-I file

Read file as an input archive.

-k

Skip corrupted file headers and I/O errors.

-l

Link files instead of copying. Can be used only with -p .

-L

Follow symbolic links.

-m

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 .

-P

Preserve ACLs. Can be used only with -p . Solaris only.

-r

Rename files interactively.

-R ID

Reassign file ownership and group information of extracted files to the user whose login ID is ID (privileged users only).

-s

Swap bytes.

-S

Swap half-words.

-t

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

-u

Unconditional copy; old files can overwrite new ones.

-v

Print a list of filenames.

-V

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

-6

Process a PWB Unix 6th Edition archive format file. Useful only with the -i option, mutually exclusive with -c and -H .

Examples

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

find . -name "*.old" -print | cpio -ocBv > /dev/rmt/0

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

cpio -icdv "*save*" < /dev/rmt/0

To move a directory tree:

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


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

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