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
 

cpio



cpio

 

flags

 [

options

]

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.)



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      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 of differing 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 archives.

-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 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.

-k

Skip corrupted file headers and I/O errors.

-l

Link files instead of copying.

-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 .

-r

Rename files interactively.

-R ID

Reassign file ownership and group information to the user's login 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 UNIX 6th Edition archive format file.

Examples

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