Previous Table of Contents Next


Arguments

The following list describes the arguments that may be passed to the cpio command.

patterns Patterns are used in conjunction with the -i option to control file retrieval. You can use the shell's filename generation characters to form regular expressions to match files you want to retrieve from an archive file.
directory The pathname of the destination directory for the -p option.

FURTHER DISCUSSION

If you are copying in or out on a character special device and cpio reaches the end of the medium, it will prompt for a new device pathname. For example, if you are saving to a floppy diskette and the diskette becomes full, cpio will display the message,

     cj> find . -print | cpio -ocB > /dev/rdiskette
     If you want to go on, type device/file name when ready.

At this point replace the floppy diskette with an empty one and type in the device pathname for the floppy drive (/dev/rdiskette) and press Return. If you do not want to continue the cpio process, you can just press Return and cpio will exit.

Copying/Extracting Files

The cpio command can be used to copy files to an archive file. You can use various ways to provide the input control pathnames to cpio. However you choose, the input format has to be the same. The cpio command looks for pathnames to files you wish to have archived. For example,

     ./myfile
     ./file1
     ./file2

would save these three files from the current directory.


NOTE:  
The input list of pathnames for cpio must contain only one pathname per line. For example, the output of echo is not valid, nor is the output of ls -x.



To generate a list of pathnames, you can use the cat, find, ls, or any other command that produces a single-column list of pathnames. Some examples follow.

     cj> ls | cpio -oc > /bck/032689

This sends cpio a list of the current directory to be saved in the archive file named 032689 in the /bck directory.

To extract the files, simply send the archive file to cpio's standard input. This can be done in various ways. The following two examples accomplish the same task.

     cj> cat /bck/032689 | cpio -ic

     or

     cj> cpio -ic < /bck/032689

Both of these commands restore all of the files archived in the /bck/032689 file.

Copying Directory Structures (Trees)

Creating archives of directory structures works almost the same way as for files. The difference is you have to provide full pathnames for all files you wish to have archived. So not only is a list of files provided, but also all subdirectories you desire to save must be sent to cpio. The most common way to accomplish this task is with the find command. For example,

     find . -depth -print | cpio -o > /dev/rdiskette

copies all of the files in the current directory and all subdirectories and files to the floppy diskette loaded in the /dev/rdiskette disk drive. Extracting files from this type backup works like normal file retrieval, with the exception you add the -d option so directories are created as they are needed.

RELATED COMMANDS

Refer to the cp, find, ls and tar commands described in modules 24, 55, 84, and 133.

RELATED FILES

The cpio command reads control information from the standard input to perform archival and retrieval functions. It writes the archive file to standard output. It writes retrievals to the proper location in the file system (directories).

BUGS/NOTES

There are several incompatiblities and quirks you should know about cpio. They are as follows.

An archive created with the -c option on SV Release 4.0 cannot be read on SV Release 3.2 or earlier systems. The -H odc header in Release 4.0 is equivalent to -c headers on earlier SV releases.

SV Release 3.2 and earlier do not understand symbolic links. Thus restoring a symbolic link to an earlier SV release causes an actual file to be created.

Pathnames are restricted to 1024 bytes unless the -H odc option is used. In which case they are restricted to 256 bytes.

Only the super-user can copy special files (devices).

Blocks are reported in 512-byte increments.

If a file has 000 permissions, contains 1 or more characters, and the user is not root, the file will not be saved or restored.

APPLICATIONS

You can use the cpio command to create an archive file that contains files or entire directory structures. You can later use these archive files to rebuild or retrieve any files stored in the archive file. The super-user may use cpio to create an entire backup of a file system. This is done by using the find command with the cpio command. If you release products, you may find it useful to archive a subdirectory or multiple directory structures.

It can also be used to copy an existing directory tree from one location to another. This allows the super-user to easily move users from one file system to another, alleviating disk space problems and providing better utilization of the system's disk space.

Normally, cpio is used to transport data between systems. It writes data in a stream format, thus saving space and time when creating a tape backup. For archival of information to be used by the program linker (ld) you use ar. If you plan on saving archives to tape for backup purposes, you might want to consider using the tar command.

TYPICAL OPERATION

In this activity you use the cpio command to store a set of files, list the table of contents of the archive file, and unarchive a few of the files. Begin at the shell prompt.

1.  Type ls | cpio -oc > /tmp/mycpio and press Return. This creates an archive file containing all the files in your current directory.
2.  Type cpio -ict < /tmp/mycpio and press Return to display a table of contents for the files stored in the archive file.
3.  Type cpio -icr < /tmp/mycpio and press Return to rename some of the files as they are restored from the archive file.
4.  Press Return on each file until you reach the file named file1.
5.  When cpio prompts with the file named file1, type myfileagain and press Return.
6.  Continue pressing Return until cpio exits. If you like, you can press Del to exit cpio immediately. You now have a new file named myfileagain.
7.  Turn to Module 133 to continue the learning sequence.


Previous Table of Contents Next