Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)

Using Archiving Utilities
Archiving utilities can simplify movement of large numbers of files between systems. Open Systems
Services supports tar, cpio, and pax (pax is the standard archiving utility in the OSS
environment). tar and pax are discussed in the following subsections; cpio is not discussed in
this guide because it is rarely used.
The tar Utility
The tar utility saves and restores data from traditional tar format archives. The actions of the
tar utility are controlled by one required flag and one or more optional flags. Other arguments
for the tar utility are file or directory names, specifying the files to archive or restore. In all cases,
appearance of a directory name refers to the files and (recursively) subdirectories of that directory.
Some sample tar commands are as follows:
To archive all.c and.h files in the current directory, enter:
tar -cvf tarfile *.c *.h
To archive files in the sourcedir directory, enter:
tar -cvf tarfile sourcedir
To list archive files in the tarfile archive file, enter:
tar -tvf tarfile
To extract all files in the tarfile archive file, enter:
tar -xvf tarfile
To extract only.c and.h files from the tarfile archive file into the current directory, enter:
tar -xvf tarfile *.c *.h
The pax Utility
The pax utility supports ustar and cpio archive formats. It reads, writes, and lists members of
an archive file, and copies files and directory hierarchies. It also supports disk and tape media.
The pax utility runs under OSS. It creates ustar archive files by default. If cpio archives are
required, the -x cpio argument must be given. Guardian archive files in the /G directory can
also be read and written using the pax utility. Using the -f flag overrides the default standard
input or output.
The following examples demonstrate some of the major capabilities of the pax utility:
To copy the files in the current directory to magnetic tape using the /G/tape output file:
$ pax -w -f /G/tape -b 10b .
To extract all the files from an archive file into the current directory hierarchy:
$ pax -r -f archive.pax
Files in the archive that use relative path names will be installed in the current directory; files
with absolute path names will be installed wherever their pathnames indicate.
To extract only the C source files from an archive file stored on the magnetic tape:
$ pax -r -f /G/tape *.c
In this example, existing files will be not be overwritten. To overwrite existing files, include the
-Wclobber flag on the pax command.
The pax utility can also take its input from the standard input file and write to an archive file.
The following example uses the find command to find all C source files in the current directory:
$ find . -name "*.c" -print | pax -w -f files.pax
For more information about the pax utility, refer to the pax(1) reference page either online or in
the Open System Services Shell and Utilities Reference Manual.
Moving or Accessing Source Files 37