I have a file compressed in *.txz. After unpacking it I received a *.tar file. Is there any way to unpack it twice with one command? I mean unpack file (*.tar).txz with one command?

For know I'm do it like this:

xz -d file.txz
tar xvf file.tar

But I wonder if there is nicer way.

3 Answers 3

xz -d < file.tar.xz | tar xvf -

That's the same as with any compressed archive. You should never have to create an uncompressed copy of the original file.

Some tar implementations like recent versions of GNU tar have builtin options to call xz by themselves.

With GNU tar or bsdtar:

tar Jxvf file.tar.xz

Though, if you've got a version that has -J, chances are it will detect xz files automatically, so:

tar xvf file.tar.xz

will suffice.

If your GNU or BSD tar is too old to support xz specifically, you may be able to use the --use-compress-program option:

tar --use-compress-program=xz -xvf file.tar.gz

One of the advantages of having tar invoke the compressor utility is that it is able to report the failure of it in its exit status.

Note: if the tar.xz archive has been created with pixz, pixz may have added a tar index to it, which allows extracting files individually without having to uncompress the whole archive:

pixz -x path/to/file/in/archive < file.tar.xz | tar xvf -
  • I have to use this one: tar --use-compress-program=xz -xvf file.tar.gz Thanks! Feb 13, 2015 at 12:01

This should be the way to go tar Jxvf file.txz


Unpacking is probably not the right terminology. You can decompress with xz and untar with tar.

The manual page for GNU tar (man tar, GNU tar is default on Debian) specifies that you can use:

-I, --use-compress-program PROG
      filter through PROG (must accept -d)

and xz supports the -d option, so you can use:

tar --use-compress-program xz xvf file.txz 

What is far less clear from the man page is that -xz and -J are shorthands for --use-compress-program xz or -I xz.

And what is not specified at all in the man page is that you can just do

tar xvf file.txz 

in GNU tar and that it will recognise the tar file as being compressed with xz.

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.