2

How to convert .tar.gz to .tar.xz?

I have a bunch of .tar.gz files that I would like to convert to .tar.xz for a better compression.

How to do this efficiently? A command like this would be great: How do I convert tar.bz2 to tar.gz?.

Here are the two commands I'm using to create a tar gz and tar xz:

  • TAR GZ tar czf folder.tar.gz folder
  • TAR XZ (LZMA) tar cfJ folder.tar.xz folder

Is there a better way than: tar xvzf folder.tar.gz && tar cfJ folder.tar.xz folder && rm -rf folder?

2

That command in your nearly duplicate question can be modified to use gunzip as a decompressor and xz to achieve exactly the same result.

gunzip2 -c < file.tar.gz | xz -c > file.tar.xz

-c in both cases tells the program to output to stdout. In the case of gunzip it receives data from stdin via < file.tar.gz and is then piped (|) to xz. xz then is told the same, with its output piped to your output file.

gunzip should be effectively the same as gzip -d

| improve this answer | |
2

The incantation you seek is:

gzip -cd file.tar.gz | xz > file.tar.xz
rm file.tar.gz

If you have many CPU cores and want maximum possible compression:

gzip -cd file.tar.gz | pxz -9 > file.tar.xz
rm file.tar.gz
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.