Using the Pax Archiving Tool


Over the years , a variety of UNIX operating systems have arisen, resulting in a variety of similar but incompatible file archiving formats. Even tools that go by the same name may use slightly different storage formats on different systems. This can lead to big problems when trying to archive and retrieve data in a multiplatform environment. Fortunately, there is a solution.

The pax program is a POSIX standard utility that can read and write a wide variety of archive formats. An RPM package for pax is included with Fedora and RHEL. If it is not already installed, to get the latest version of pax (provided you have an Internet connection), type the following as root user :

 #  yum install pax  

If you don't have an Internet connection, mount the CD/DVD containing your Fedora or RHEL distribution, change to the RPMS directory, and then use the rpm command to install pax.

 #  rpm -Uhv pax-*  

Remember you need to be logged in as root when installing software with the rpm command. Pax takes a variety of command-line options. The last parameter is usually the file or directory to archive. You may use wildcard characters such as * or ? to specify multiple files or directories. The options you will use most often include the -r and -w parameters for specifying when you are reading or writing an archive. These are usually used in conjunction with the -f parameter, which is used to specify the name of the archive file.

By using pax parameters in different combinations, it is possible to extract an archive, create an archive, list the contents of an archive, or even copy an entire directory hierarchy from one location to another. Table 13-8 shows a few examples of the pax command in action.

Table 13-8: Examples of pax Use
Open table as spreadsheet

Pax Command

Description

pax -f myfiles

List the contents of the archive named myfiles .

pax -r -f myfiles

Extract the contents of the archive named myfiles .

pax -w -f myfiles /etc

Create an archive named myfiles containing everything within the /etc directory.

pax -w -f myfiles *.txt

Archive all of the files in the current directory that have a .txt file extension.

pax -r -w / olddir / newdir

Copy the entire contents of the directory /oldir into a new directory called /newdir .

pax -w -B 1440000 -f /dev/fd0 *

Archive the contents of the current directory onto multiple floppy disks.

pax -w -x cpio -f myfiles *

Archive the contents of the current directory into an archive file named myfiles using the cpio format.

pax -r -U mary -f backups

Extract all of the files owned by user mary from the archive named backups .

Note that by leaving off both the -r and -w options, you cause pax to simply list the contents of the archive. If you specify both the -r and -w options, then you should leave off the -f option and supply source and destination directories instead. This will cause the source directory to be completely cloned in the specified destination directory.

You can use additional parameters to further modify the pax command's behavior. For example, you can use the -x option in conjunction with the -w option to specify the specific archive type to create, or you can use the -B option to specify the number of bytes to write to each volume of a multivolume archive.

Table 13-9 describes the many optional parameters to the pax command.

Table 13-9: Options to pax
Open table as spreadsheet

Pax Options

Description

-r

Read files from an archive.

-w

Write files to an archive.

-a

Append files to a previously created archive.

-b blocksize

Specify the archive's data block size . It must be a multiple of 512.

-c pattern

Match all files except those that match the specified pattern.

-d

Match filename wildcards against file or directory names only, not the complete path .

-f archive

Specify the name of the archive.

-i

Interactively rename files when archiving.

-k

Do not overwrite existing files.

-l

Link files with hard links when in copy mode ( -r -w ).

-n pattern

Match only the first file that matches the supplied pattern.

-o options

Extra options specific to the archiving format used.

-p string

Specify the file characteristics to retain when archiving or copying. Read the pax man page for more information on this option.

-s replstr

Modify the archived filenames using the supplied regular expression.

-t

Preserve the access times of archived files.

-u

Do not overwrite files with older versions.

-v

Provide verbose output when running.

-x format

Specify the format of the archive. Valid formats include cpio, bcpio, sv4cpio, sv4crc, tar , and ustar . The default is to use ustar when creating an archive. Pax will automatically determine the correct file type when reading an archive.

-z

Indicates that gzip should be used to compress and decompress the archive.

-B bytes

Specify the number of bytes per archive volume. Use this option to create multivolume archives on removable media.

-D

Do not overwrite existing files with files that have an older inode modification time.

-E limit

Limit the number of times pax will retry on encountering a read or write error.

-G group

Select files based on a group name or GID. To select by GID, place a # sign in front of the group number.

-H

Follow only command-line symbolic links while performing a physical file system traversal.

-L

Follow all symbolic links when traversing a directory hierarchy.

-P

Do not follow symbolic links. This is the default.

-T time

Select files based on their modification time. Read the pax man page for complete discussion of this parameter's syntax.

-U user

Select files based on the owner's user name, or by UID with a # sign in front of it.

-X

Do not traverse into directories that reside on a different device.

-Y

This option is the same as the -D option, except that the inode change time is checked using the pathname created after all the filename modifications have completed.

-Z

This option is the same as the -u option, except that the modification time is checked using the pathname created after all the filename modifications have completed.

As you can see, pax is a very flexible and powerful archiving tool. It can be particularly helpful in migrating data from older legacy systems to your new Linux system. When you are faced with the task of recovering archived data from an antiquated or even nonfunctioning UNIX system, the multiple file format support of pax can be a literal lifesaver.




Fedora 6 and Red Hat Enterprise Linux Bible
Fedora 6 and Red Hat Enterprise Linux Bible
ISBN: 047008278X
EAN: 2147483647
Year: 2007
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net