如何将tar文件从gnu格式转换为pax格式

nos*_*sid 7 tar conversion

一方面我有很多用gnu格式创建的 tar 文件,另一方面我有一个只支持pax(又名posix)格式的工具。我正在寻找一种简单的方法将现有的 tar 文件转换为 pax 格式 - 无需将它们解压缩到文件系统并重新创建档案。

GNU tar 支持这两种格式。但是,我还没有找到一种简单的转换方法。

如何将现有的gnu tar 文件转换为pax

[我在 superuser.com 上问了同样的问题,一位评论者建议将问题迁移到 unix.stackexchange.com。]

ire*_*ses 6

您可以使用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
Run Code Online (Sandbox Code Playgroud)

@archive是神奇的选择。从联机帮助页

@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.
Run Code Online (Sandbox Code Playgroud)