How to convert tar file from gnu format to pax format

conversiontar

On the one hand I have a lot of tar files created with gnu format, and on the other hand I have a tool that only supports pax (aka posix) format. I am looking for an easy way to convert the existing tar files to pax format – without extracting them to the file system and re-create the archives.

GNU tar supports both formats. However, I haven't found an easy way to the conversion.

How can I convert the existing gnu tar files to pax?

[I asked the same question on superuser.com, and a commenter recommended to migrate the question to unix.stackexchange.com.]

Best Answer

You can do this using bsdtar:

ire@localhost: bsdtar -cvf pax.tar --format=pax @gnu.tar
ire@localhost:file gnu.tar
gnu.tar: POSIX tar archive (GNU)
ire@localhost:file pax.tar
pax.tar: POSIX tar archive

@archive is the magic option. From the manpage:

@archive
     (c and r mode only) The specified archive is opened and the
     entries in it will be appended to the current archive.  As a sim-
     ple example,
       tar -c -f - newfile @original.tar
     writes a new archive to standard output containing a file newfile
     and all of the entries from original.tar.  In contrast,
       tar -c -f - newfile original.tar
     creates a new archive with only two entries.  Similarly,
       tar -czf - --format pax @-
     reads an archive from standard input (whose format will be deter-
     mined automatically) and converts it into a gzip-compressed pax-
     format archive on stdout.  In this way, tar can be used to con-
     vert archives from one format to another.
Related Question