cpio(C) 06 January 1993 cpio(C) Name cpio - copy file archives in and out Syntax cpio -o [ aBcLUvV ] [ -Cbufsize ] [[ -Ofile ] [ -Kvolumesize ] [ -Mmessage ]] cpio -i [ AbBcdkmrtTuvVfsS6 ] [ -Cbufsize ] [[ -Ifile ] [ -Mmessage ]] [ pattern ... ] cpio -p [ adlLmuvV ] directory Description cpio -o (copy out) reads the standard input to obtain a list of pathnames and copies those files onto the standard output together with pathname and status information. Output is padded to a 512-byte boundary by default. cpio -i (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 patterns are selected. patterns are regular expressions given in the filename-generating notation of sh(C). In patterns, metacharac- ters ?, *, and [ ... ] match the slash (/) character, and backslash (\) is an escape character. A ``!'' metacharacter means not. (For example, the !abc* pattern would exclude all files that begin with abc.) Multiple patterns may be specified and if no patterns are specified, the default for patterns is ``*'' (that is, select all files). Each pattern must be enclosed in double quotes; otherwise, the name of a file in the current directory is used. Extracted files are conditionally created and copied into the current directory tree based upon the options described below. If cpio is used to copy files by a process without appropriate privileges, the access permissions are set in the same fashion that creat() would have set them when given the mode argument, matching the file permissions supplied by the cmode field of the cpio format. The owner and group of the files will be that of the current user unless the user is super user, which causes cpio to retain the owner and group of the files of the previous cpio -o. NOTE: 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 mes- sage and not replace the file. (The -u option can be used to uncondi- tionally overwrite the existing file.) cpio -p (pass) reads the standard input to obtain a list of path names 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 meanings of the available options are: -a Reset access times of input files after they have been copied. Access times are not reset for linked files when cpio -pla is specified. -A Suppresses absolute filenames. A leading ``/'' character is removed from the filename during copy-in. If a pattern is pro- vided, it should match the relative (rather than the absolute) pathname. -b Reverse the order of the bytes within each word. Use only with the -i option. -B Input/output is to be blocked 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 meaning- ful only with data directed to or from a character-special de- vice, for example, /dev/rdsk/f0q15dt.) -c Write header information in ASCII character form for portability. Always use this option when origin and destination machines are different types. -Cbufsize Input/output is to be blocked 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 1K multiple. -d Directories are to be created as needed. -f Copy in all files except those in patterns. (See the paragraph on cpio -i for a description of patterns.) -Ifile 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. Use only with the -i option. -k 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 ter- minate 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. -Kvolumesize Specifies the size of the media volume. Must be in 1K blocks. For example, a 1.2M floppy disk has a volumesize of 1200. Must include the -C option with a bufsize multiple of 1K. 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.) -l Whenever possible, link files rather than copying them. Usable only with the -p option. -L Follow symbolic links. -m Retain previous file modification time. This option is ineffec- tive on directories that are being copied. -Mmessage 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 con- tinue. -Ofile 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. Use only with the -o option. -r Interactively rename files. If the user types a null line, the file is skipped. If the user types a ``.'', the original path- name will be copied. (Not available with cpio -p.) -s Swap bytes within each half word. Use only with the -i option. -S Swap halfwords within each word. Use only with the -i option. -T Truncate long filenames to 14 characters. Use only with the -i option. -t Print a table of contents of the input. No files are created. -u Copy unconditionally (normally, an older file will not replace a newer file with the same name). -U Inform cpio that you are using a SCSI device. You do not need to use the -K option to specify the volume size. -v Verbose: causes a list of filenames to be printed. When used with the -t option, the table of contents looks like the output of an ls -l command (see ls(C)). -V Special Verbose: print a dot for each file seen. Useful to assure the user that cpio is working without printing out all filenames. -6 Process an old (that is, UNIX System Sixth Edition format) file. Use only with the -i option. NOTE: cpio assumes 4-byte words. Files may be archived with relative or absolute pathnames. Absolute path- names 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 directory /u/bulls: 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 per- mission 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 paths. If cpio reaches end of medium (end of a diskette for example) when writ- ing 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 (/dev/rdsk/f0q15dt for example) 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 car- riage return alone causes the cpio process to exit.) Examples The following examples show cpio being used to create, verify and read archives, and to copy a complete directory structure. 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 ls(C) 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(C), you could use find(C), echo(C), cat(C), 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 speci- fying 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 destination direc- tory. If you use find with cpio, you can place conditions on which files are to be archived. For example, you can choose to archive: + Files of a given size (using the -size option of find). + 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 (-ctime). + Files with certain permissions, such as executable files (-perm). + Files owned by certain users (-user) or groups (-group). 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 read-only directories. 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: cd /u find . -depth -print | cpio -ocvB -O/dev/rct0 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 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 directories. If the archive had been written to a floppy drive, you might use: cpio -icdv -I/dev/rct0 "memo/a1" "memo/b*" The -d option will cause cpio to create directories as needed. 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 -icvt -I/dev/rct0 In the final example, cpio -p takes the filenames piped to it and copies or links (-l option) those files to another directory (../newdir), keep- ing the modification time of the copied files (-m option). find . -depth -print | cpio -pdlmv ../newdir See also cat(C), echo(C), find(C), ls(C), tar(C) and cpio(F). Notes Pathnames are restricted to 255 characters. Only the super user 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 or restored. When find is used in conjunction with cpio, if the -L flag is used with cpio (follow symbolic links), then the -follow expression must be used with find. Standards conformance cpio is conformant with: AT&T SVID Issue 2; and X/Open Portability Guide, Issue 3, 1989.