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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
Ubuntu includes GNU tar, which recognizes the format by itself! One command works with any supported compression method, per the manual.
tar xf archive.tar.xz tar xf archive.tar.gz tar xf archive.tar
etc. If tar gives a
Cannot exec error, you may need to
sudo apt install xz-utils first.
tar -xJf file.pkg.tar.xz
-J is the flag that specifically deals with .xz files.
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
tar to untar the file.
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.
I had the same problem, the
tar xf command was not able to extract it.
To fix this, you need to install the
The solution was:
sudo apt-get install xz-utils
tar xf myfile.tar.xz
tar -xvf package.tar.xz
-x - extract files
-v - verbosely list files processed
-f - use specified archive file
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. For example,
tar --use-compress-program xz -cf example.tar.xz file1 file2 file3
tar --use-compress-program xz -xf example.tar.xz
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!
I like dtrx
sudo apt install dtrx dtrx your-file.tar.xz
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 -
Ubuntu comes with Python (Python 2.7 and Python 3), which contains the necessary modules for extracting archives. So if for whatever reason
tar command is missing (say your sysadmin has removed it and you don't have
sudo privillege to install it), one can use:
python3 -c 'import tarfile,sys; b = tarfile.open(sys.argv);print(b.extractall())' ./archive.xz
As a short script,that's more readable as:
#!/usr/bin/env python3 import tarfile,sys with tarfile.open( sys.argv ) as fd: fd.extractall()
Suppose I created an
.xz file with
tar cJf thing.xz /etc/passwd. The archive will contain
etc directory with
passwd file inside. Using the above script will result in
etc directory created in your current working directory, and within it will be
passwd file. Of course, this can always be extended by specifying path where you want to extract inside the
unar is quite a nice simple program and easy to type, to unarchive almost any format including 7z and RAR
if you use --install-suggests or have configured
apt to install suggested packages,
unar will suggest and install many GUI GNUStep programs which are not what you want
sudo apt install --no-install-suggests unar unar linux-source.tar.xz
it will create the output directory
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?