The cpio Command Tape−Related Commands

In most cases the use of the tar command involves the following command options: To tar data create an archive: tar −cvf devrmtmt_device files_to_tar • To list the archive tar−ed data: tar −tvf devrmtmt_device • To untar extract all tar−ed data: tar −xvf devrmtmt_device • To untar extract selected tar−ed data: tar −xvf devrmtmt_device files_to_untar • Using the v verbose option to show exactly what tar is doing is recommended. Sometimes, it can take quite a while for the command to terminate, and it is always good to know what happens in the meantime.

12.2.2 The cpio Command

The cpio command copies files into and out of archives for storage, moving, and backups. Archives can be ordinary files, directories, or backup media such as tape or floppy disks. cpio has several advantages over the tar command: It can back up arbitrary sets of files. • It can back up special device files and so is suitable for full system backups on small systems. • It packs data on tape significantly more efficiently than tar. • On restore, it skips over bad spots on the tape while tar dies in such cases. • cpio takes its input from the standard input i.e., keyboard, not from files specified as arguments. It waits for input names of files typed in one line terminated by CTRL−D. The cpio command can be used in three different ways, defined by three different generic formats. Each format uses different required options that cannot be combined. There are additional options that can be used in all three command formats. The syntax is: cpio −o [acBv] cpio −i [option] [pattern] cpio −p [option] directory The required and additional options have the following meaning: Required Options Meaning −o [option] Causes cpio to read a list of file names from its standard input and combine them into an archive file, which it prints as its standard output copy out 276 −p [option] directory Causes cpio to read a list of ordinary files from its standard input and copy them to the specified directory Additional Options Meaning a Resets access times of input files after they are copied c Writes the header information in ASCII characters for portability to other machines d Creates directories as needed; used when directories are specified to be copied f Copies only files not matched by pattern l Creates links to files in the new directories instead of copying them if possible m Does not change modification time of files when copying them r Allows files to be renamed as they are copied; cpio waits for a new name t List the names of the input files without copying them u Pushes cpio to overwrite files if they already exist ordinarily, cpio does not copy files if they already exist v Prints a list of the files being copied The cpio command is usually combined piped with other UNIX commands to perform a requested command sequence often within scripts. The manual use of the command from the command line is not very convenient, but still workable. The need to handle special device files makes this command unavoidable. Here are a few examples: To archive all files, starting in the current directory and continuing with subsequent subdirectories, onto the magnetic tape identified by the tape device file 0m: find . −print | cpio −o devrmt0m • To copy all files in the directory dir1 into dir2: ls dir1 | cpio −p dir2 • Although it works for any directory, the example is used primarily to copy special device files: ls devdir1 | cpio −p devdir2 The d option is required if the directory dir2 does not already exist.

12.2.3 The dd Command