Copies files into and out of archive storage and directories. This document describes the AIX cpio command and the System V cpio command.
cpio -o [ a ] [ c ] [ v ] [ B | C Value ] <FileName >Output
cpio -i [ b ] [ c ] [ d ] [ f ] [ m ] [ M ] [ r ] [ s ] [ t ] [ u ] [ v ] [ S ] [ 6 ] [ B | C Value ] [ Pattern... ] <Input
cpio -p [ a ] [ d ] [ l ] [ m ] [ M ] [ u ] [ v ] Directory <FileName
The cpio command copies files into and out from a cpio archive. The cpio archive may span multiple volumes. The -i, -o, and -p flags select the action to be performed.
Attention: If you redirect the output from the cpio command to a special file (device), you should redirect it to the raw device and not the block device. Because writing to a block device is done asynchronously, there is no way to know if the end of the device is reached.
Note:
- The cpio command is not enabled for files greater than 2 Gig in size due to limitations imposed by XPG/4 and POSIX.2 standards.
- cpio does not preserve the sparse nature of any file that is sparsely allocated. Any file that was originally sparse before the restoration will have all space allocated within the filesystem for the size of the file.
The cpio -o command reads file path names from standard input and copies these files to standard output, along with path names and status information. Avoid giving the cpio command path names made up of many uniquely linked files, as it may not have enough memory to keep track of them and would lose linking information.
The cpio -i command reads from standard input an archive file created by the cpio -o command and copies from it the files with names that match the Pattern parameter. These files are copied into the current directory tree. You can list more than one Pattern parameter, using the file name notation described in the ksh command. Note that in this application the special characters * (asterisk), ? (question mark), and [...] (brackets and ellipses) match the / (slash) in path names, in addition to their use as described in the ksh command. The default for the Pattern parameter is an * (asterisk), selecting all files in the Input. In an expression such as [a-z], the minus sign means through according to the current collating sequence.
A collating sequence can define equivalence classes for use in character ranges.
The cpio -p command reads file path names from standard input and copies these files into the directory named by the Directory parameter. The specified directory must already exist. If these path names include directory names that do not already exist, you must use the d flag to cause the specified directory to be created.
Note: You can copy special files only if you have root user authority.
Directory | Specifies the directory. |
<FileName | Specifies a list of file names for the cpio command to use as input. |
>Output | Specifies the output device such as a diskette or file. For more information on using tape devices see the rmt special file. |
<Input | Specifies the input device (where Input is the Output file created by the cpio -o command). For more information on using tape devices, see the rmt special file. |
Pattern | Specifies the pattern (as described in the ksh command) to be used with the command. The default for the Patternparameter is an * (asterisk), selecting all the files in the Input. |
All flags must be listed together, without any blanks between them. Not all of the following flags can be used with each of the -o, -i, and -p flags.
a | Resets the access times of the source files to their previous times. |
b | Swaps both bytes and halfwords.
Note: If there is an odd number of bytes or halfwords in the file being processed, data can be lost. |
B | Performs block input and output using 512 bytes to a record.
Note: When using the B or C options to extract or create a tape archive, the blocking factor must be a multiple of the physical block size for that tape device. |
c | Reads and writes header information in ASCII character form. If a cpio archive was created using the c flag, it must be extracted with c flag. |
C Value | Performs block input and output using the Value parameter times 512 bytes to a record. For instance, a -C2 flag changes the block input and output sizes to 1024 bytes to a record. |
d | Creates directories as needed. |
-E | The -E option requires one of
the following arguments. If you omit the -E option, warn is the default cpio behavior.
|
f | Copies all files except those matching the Pattern parameter. |
l | Links files rather than copying them, whenever possible. This flag can only be used with the cpio -p command. |
m | Retains previous file modification time. This flag does not work when copying directories. |
M | Retains previous file modification time even when directories are copied. |
r | Renames files interactively. If you do not want to change the file name, enter a single period or press the <Enter> key. In the latter case, the cpio command does not copy the file. |
s | Swaps bytes. This flag is used only with the cpio -i command.
Note: If there is an odd number of bytes in the file being processed, data can be lost. |
S | Swaps halfwords. This flag is usable only with the cpio -i command.
Note: If there is an odd number of halfwords in the file being processed, data can be lost. |
t | Creates a table of contents. This operation does not copy any files. |
u | Copies unconditionally. An older file now replaces a newer file with the same name. |
v | Lists file names. If you use this with the t flag, the output looks similar to that of the ls -l command. |
6 | Processes an old file (for example, one written in UNIX Sixth Edition format). This flag is usable only with the cpio -i command. |
This command returns the following exit values:
0 | Successful completion. |
>0 | An error occurred. |
cpio -ov <filenames >/dev/rfd0
This copies the files with path names listed in the filenames file in a compact form onto the diskette (>/dev/rfd0). The v flag causes the cpio command to display the name of each file as it is copied. This command is useful for making backup copies of files. The diskette must already be formatted, but it must not contain a file system or be mounted.
Note: Files with uid's and gid's greater than 65535 cannot be archived using the cpio command. In such instances, the user should use backup and restore.
ls *.c | cpio -ov >/dev/rfd0
This copies all the files in the current directory whose names end with .c
find . -print | cpio -ov >/dev/rfd0
This saves the directory tree that starts with the current directory (.) and includes all of its subdirectories and files. Do this faster by entering:
find . -cpio /dev/rfd0 -print
The -print entry displays the name of each file as it is copied.
cpio -itv </dev/rfd0
This displays the table of contents of the data previously saved onto the /dev/rfd0 file in the cpio command format. The listing is similar to the long directory listing produced by the ls -l command. To list only the file path names, use only the -it flags.
cpio -idmv </dev/rfd0
This copies the files previously saved onto the /dev/rfd0 file by the cpio command back into the file system (specify the -i flag). The d flag allows the cpio command to create the appropriate directories if a directory tree is saved. The m flag maintains the last modification time in effect when the files are saved. The v flag causes the cpio command to display the name of each file as it is copied.
cpio -ir </dev/rfd0
The -r flag causes the cpio command to ask you whether to rename each file before copying it from diskette. For example, the message:
Rename <prog.c>
asks whether to give the file saved as prog.c a new name as it is copied. To rename the file, type the new name and press the Enter key. To keep the same name, you must enter the name again. To avoid copying the file at all, press the Enter key.
mkdir /home/jim/newdir find . -print | cpio -pdl /home/jim/newdir
This duplicates the current directory tree, including the current directory and all of its subdirectories and files. The duplicate is placed in the new /home/jim/newdir directory. The l flag causes the cpio command to link files instead of copying them, when possible.
Note: The performance of cpio to the 9348 Magnetic Tape Unit Model 12 can be improved by changing the default block size. To change the block size, enter the following at the command line:chdev -1 <device_name> -a block_size=32k
/usr/bin/cpio | Contains the cpio command. |
The find command, ksh command, ln command, ls command.
The cpio file format, rmt special file.
The Backup Overview for System Management in AIX 5L Version 5.2 System Management Concepts: Operating System and Devices provides information on different methods of backing up, restoring process, different types of backup media, and guidelines for backup policies.
The Directory Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices explains working with directories and path names.
The File Systems in AIX 5L Version 5.2 System Management Concepts: Operating System and Devices explains file system types, management, structure, and maintenance.
The Files Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices provides information on working with files.
Copies files into and out of archive storage and directories.
cpio -i [ -b ] [ -B ] [ -c ] [ -d ] [ -f ] [ -k ] [ -m ] [ -r ] [ -s ] [ -S ] [ -T ] [ -t ] [ -u ] [ -v ] [ -V ] [ -6 ] [ -C bufsize ] [ -E file ] [ -H hdr ] [ -I file [ -M message ] ] [ -R ID ] ] [ Patterns ...]
cpio -o [ -a ] [ -A ] [ -B ] [ -c ] [ -L ] [ -v ] [ -V ] [ -C bufsize ] [ -H hdr ] [ -K mediasize ] [ -O file [ -M message ] ]
cpio -p [ -a ] [ -d ] [ -l ] [ -L ] [ -m ] [ -u ] [ -v ] [ -V ] [ -R ID ] Directory
The cpio command copies files into and out of an archive. The -i, -o and -p options select the action to be performed. The following list describes each of the actions. The -o, -p and -i options are mutually exclusive.
The cpio -i command reads the standard input of an archive file created that was using the cpio -o command, and copies the files with names that match the pattern parameter. The pattern parameter is a regular expression given with general notation of ksh. These files are copied into the current directory tree. More than one pattern parameter can be used, using the file name notation described in the ksh command. The patterns can be special characters * (asterisk), ? (question mark), and [...] (brackets and ellipses). The default for the pattern parameter is an * (asterisk), selecting all files in the input. In an expression such as [a-z], the minus sign means through according to the current collating sequence.
The permissions of the files will be those of the previous cpio -o. Owner and group permissions will be the same as the current user. If this is true, owner and group permissions will be the same as those resulting from the previous cpio -o. Blocks are reported in 512-byte quantities.
If cpio -i tries to create a file that already exists and the existing file is the same age or younger (newer), cpio will output a warning message and not replace the file. On the other hand if the file being extracted is older than the one in the cpio archive then the existing file will be replaced without any warning from the command.
cpio -o reads the standard input to obtain a list of path names and copies those files onto the standard output together with path name and status information.
cpio -p reads the standard input to obtain a list of path names of files and copies these files into the directory named by the Directory parameter. The specified directory must already exist. If these path names include directory names that do not already exist, you must use the d flag to cause the specified directory to be created. By default the Access Control List's (ACL) are transferred [copied] from source file to destination file with this option only.
find . | /usr/sysv/bin/cpio -oc >/dev/rmt0The -c option ensures that the file is made portable to other machines. Instead of find you can also use ls, cat, echo and so on to pipe a list of names to cpio. The output could also be redirected to a regular cpio file instead of a device.
/usr/sysv/bin/cpio -icdI arfileHere all the files are extracted from the cpio archive and the -d option ensures that the required directory paths are created as when required.
/usr/sysv/bin/cpio -icd < arfileThe -d option ensures that all the required directories are created under the current directory. The standard input can be used only if -I flag is not specified.
/usr/sysv/bin/cpio -icduI arfile
/usr/sysv/bin/cpio -ickudI arfile
ls | /usr/sysv/bin/cpio -oca > arfile
cat ar | /usr/sysv/bin/cpio -ickud "a*"This command extracts all the files starting with letter "a".
cat ar | /usr/sysv/bin/cpio -itvThe verbose option (-v) ensures that the list given by -t option is listed in a very similar way as ls -l command.
find . -print | /usr/sysv/bin/cpio -pd /home/user1/newdirThe entire directory tree from current directory is copied to /home/user1/newdir. The -d option ensures that directories are created as necessary.
find . -name "*.o" -print | /usr/sysv/bin/cpio -pdlmv /home/user1/newdirIn this example only the .o files under the directory tree are copied to /home/user1/newdir.
ls d* | /usr/sysv/bin/cpio -oAO /tmp/arIn this example, all files starting with "d" in the current directory will be appended to the cpio archive.
cat ar | /usr/sysv/bin/cpio -i -E EfileIn this example, cpio extracts only those files that are listed in the regular file "Efile", provided the specified file name exists in the archive.
ls d* | /usr/sysv/bin/cpio -pdl /home/user2/newdirIn this example, the -l flag ensures all the file names starting with the character "d" are hard linked to the /home/user2/newdir, the directory specified. Hard linking across file systems is not allowed, thus the -l option cannot be used when the destination directory is in any other filesystem.
/usr/sysv/bin/cpio | Contains the System V cpio command. |
The /usr/bin/cpio command, tar command, dd command, pax command.