Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm used to extracting tarballs with a -xfz flag, which handles gzip and bzip2 archives.

Recently I've run into a .tar.xz file and I would like to uncompress it in one step using tar, how can I do that?

share|improve this question
note you may have to install xz-utils if not already present – Tobias Kienzler May 10 '13 at 7:04
here's my little script that guesses tar flags for you: – shime Jul 2 '13 at 12:06
up vote 434 down vote accepted

Modern tar recognizes the format by itself! One command works with any supported compression method.

tar xf archive.tar.xz
tar xf archive.tar.gz
tar xf archive.tar


share|improve this answer
It's a feature of GNU tar. I don't know about competing implementations, but GNU tar should be the most relevant to ubuntu. – ramslök Feb 29 '12 at 2:20
if you run into tar: xz: Cannot exec: No such file or directory, install xz-utils: sudo apt-get install xz-utils – Collin Anderson Feb 11 '14 at 16:33
This is not an answer, it is a 'you don't care about the answer, even though you asked' response. Spare a thought for people who are not on 'latest' – Sean Houlihane Jan 20 '15 at 9:41
What version of tar no longer requires the specific flag? – Mark Tomlin May 13 '15 at 19:19
@SeanHoulihane, it is not an answer because the OP asked a minor XY problem. ramslök gave the OP better than was asked for, and that included an effective "You don't care about the answer, even though you asked", which was appropriate because it was true. – JonathanHayward Sep 5 '15 at 22:49


tar -xJf file.pkg.tar.xz

The -J is the flag that specifically deals with .xz files.

share|improve this answer
I wonder how many flags will we have in 2020. Like... 45 different compressions? Knowing tar switches is already a black-belt in Linux-fu. :/ – Shiki Jun 7 '13 at 15:13
@Shiki: That's probably why it doesn't make you specify the compression format flag anymore. (See ramslök's answer.) – Nate C-K Oct 23 '13 at 3:37
8 – Wordzilla Mar 25 '15 at 13:21
This should totally be the accepted answer since it answers the question for any version of tar supporting .xz – pospi Jul 8 '15 at 12:21
@pospi true (I got here looking for the BSD answer for OS X), but this is the Ubuntu SE so it makes some sense to assume GNU. – tvon Jul 30 '15 at 14:50

If for some reason the tar solutions don’t work (perhaps because you’re using the OS X built-ins), try this:

unxz < file.tar.xz > file.tar

…which is equivalent to:

xz -dc < file.tar.xz > file.tar

Then use tar to untar the file.

share|improve this answer
That should be constructable with a pipe. – gerrit Mar 20 '14 at 18:43
I feel like you could just do unxz < file.tar.xz | tar x or similar. – thirtythreeforty May 16 '14 at 14:39
this worked for me, where tar xf did not. ubuntu 12.04 – philshem Aug 14 '14 at 20:57

xz is a lossless data compressor. You will have to extract the tar ball from xz and then extract the tar:

unxz my_archive.tar.xz      # results in my_archive.tar

Then you know to extract a tar

tar -xf my_archive.tar

Source: XZ Utils - Wikipedia.

share|improve this answer

I had the same problem, the tar xf command was not able to extract it. To fix this, you need to install the xz-utils package. The solution was:

sudo apt-get install xz-utils


tar xf myfile.tar.xz
share|improve this answer

What about

tar -xvf package.tar.xz
share|improve this answer

Wow, that's a really good one. Was it done with 7zip on a Mac? Try this:

7z x -so file.tar.xz | tar xf -
share|improve this answer
Requires 7z, which isn't what he wants - he wants to do it entirely in tar. – James Jan 3 '12 at 0:08
Yes, thanks - the "xz" got me! Well, it's one step anyway :) And tar J = tar xz, so we might even write tar xzf file.tar.xz like "normal" tar xvfz file.tar.gz. So basically no difference. No dash needed before using the switch. – user8290 Jan 3 '12 at 0:19
It's almost like the answer was given in the question. :) – user8290 Jan 3 '12 at 0:26
I was thrown off too because tar zxf errored out on the .xz file, I suppose just using J all the time would be the way to go. – Jorge Castro Jan 3 '12 at 0:28
Yup! The manual page is not in sync with the source: buffer.c uses -J for lzma. – user8290 Jan 3 '12 at 0:45

If tar recognizes the compression format, you don't need a flag:

tar xvf *.tar.xz

If you need to decompress the input manually, for example because your tar is too old to recognize xz, or you need a special path:

xz -cd *.tar.xz | tar xvf -

Pipes are faster than making an uncompressed intermediate file, and use less disk space too!

share|improve this answer

Just want to add that if you have an old version of GNU tar prior to version 1.22 when the --xz and -J options became available, you could compress or decompress tar.xz files by using --use-compress-program xz. E.g.,

tar --use-compress-program xz -cf example.tar.xz file1 file2 file3<br>


tar --use-compress-program xz -xf example.tar.xz
share|improve this answer

protected by Community 2 days ago

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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