Using pax

A nice alternative to tar and cpio is pax, which is capable of unpacking archives in both these formats. Its command syntax is also simpler to learn than either tar or cpio, both of which can give a new user headaches. It also offers a neater solution than tar to the problem of exactly copying an entire directory tree complete with permissions, timestamps, and symbolic links from one place to another.

To create a pax archive file of the current directory, do the following:

This writes (-w) verbosely (-v) the file (-f) /tmp/archive.pax, archiving the current directory (. ).

To unpack the archive somewhere else, do the following:

[email protected]:/another_directory # pax -rvf archive.pax

Here we are verbosely (v) reading (r) from the archive file, and pax by default writes out the archived directories and files to disk under the current directory. To be sure that all the permissions and ownerships will be restored, you will need to do this as root.

To list the files in the archive, simply do the following:

[email protected]:/another_directory > pax -f archive.pax

If you have a gzipped tar file, you can unpack it with pax like this:

[email protected]:~/tmp> pax -rzvf archive.tgz

Here, the r option shows that you are reading from the archive, while the z indicates that you need gzip uncompression.

To unpack a cpio archive, do the following:

[email protected]:~/tmp> pax -rvf archive.cpio

To copy a directory tree preserving all ownerships and permissions, do the following:

[email protected]: / # pax -rvw -pe /source/ /path/to/destination/

Here you read (r) from the source directory and write (w) to the destination directory, while preserving (-p) everything (e) (in other words all ownerships and permissions).

Was this article helpful?

0 0

Post a comment