Comment convertir un file tar du format gnu au format pax

D'une part, j'ai beaucoup de files tar créés avec le format gnu , et d'autre part j'ai un outil qui ne supporte que le format pax (aka posix ). Je cherche un moyen facile de convertir les files tar existants au format pax – sans les extraire dans le système de files et recréer les archives.

GNU tar prend en charge les deux formats. Cependant, je n'ai pas trouvé un moyen facile à la conversion.

Comment puis-je convertir les files gnu tar existants en pax ?

[J'ai posé la même question sur superuser.com et un commentateur a recommandé de migrer la question vers unix.stackexchange.com.]

Vous pouvez le faire en utilisant 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 est l'option magique. De la page de manuel :

 @archive (c and r mode only) The specified archive is opened and the ensortinges 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 ensortinges from original.tar. In contrast, tar -c -f - newfile original.tar creates a new archive with only two ensortinges. 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. 

L'user Random832 a écrit:

[…] créer un file tar vide […]
Disclaimer: Je n'ai pas testé ce script.

Dieu te bénisse! Tu m'as donné des idées. J'ai testé votre script, mais si quelqu'un crée un file tar vide, tar ne le considère pas comme un file "posix tar". J'ai donc écrit un script qui crée un file "posix tar" avec quelque chose à l'intérieur, et enfin le supprime. Je l'ai nommé "gnu2posix", les gens peuvent l'utiliser librement:

 #!/bin/bash set -o nounset ### // Convert a tar file, from the "gnu tar" format to the "posix tar" one (which in Windows, for example, allows seeing correctly all of the utf-8 characters of the names of the files) NAME_PROGRAM=$(basename "$0") alert() { echo "$@" >&2 ; } alert_about_usage() { echo "The usage of this program is: $NAME_PROGRAM FILE_TO_CONVERT RESULTING_FILE" >&2 } if [[ $# != 2 ]]; then alert "ERROR: the program \"$NAME_PROGRAM\" needs two arguments, but it has received: $#." alert_about_usage exit 1; fi file_to_convert="$1" if [[ ! -f "$file_to_convert" ]]; then error "ERROR: the program \"$NAME_PROGRAM\" can't access any file with this path: \"$file_to_convert\"." alert_about_usage exit 1; fi resulting_file="$2" # // Create a file with something inside, in this case, the "." folder (without its contents). This way, a real "posix tar" is created tar --format=posix -cf "$resulting_file" . --no-recursion # // Add "$file_to_convert", finally getting a "posix tar" file tar -Avf "$resulting_file" "$file_to_convert" # // Just in case, delete the "." folder from the file tar -f "$resulting_file" --delete "." # // End of file 

Gnu tar a une option "concaténer", mais exige que l'archive de destination existe déjà en raison du cas d'utilisation prévu.

 tar --format=posix -cvf converted.tar --files-from=/dev/null # create an empty tar file tar --format=posix -Avf converted.tar original.tar 

Disclaimer: Je n'ai pas testé ce script.