Open tar xz file in linux

How do I uncompress a tarball that uses .xz?

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?

Better Question to ask than how to do this with tar: Use unar or 7z and never worry about choosing the right program for your type of archive again. This is the only feasible solution looking forward with more and more archive types coming. Unless you care about the technical details.

12 Answers 12

Ubuntu includes GNU tar, which recognizes the format by itself! One command works with any supported compression method, per the manual.

# The same command handles any compression format! Ex: tar xf archive.tar.xz # for .tar.xz files tar xf archive.tar.gz # for .tar.gz files tar xf archive.tar # for .tar files 

etc. If tar gives a Cannot exec error, you may need to sudo apt install xz-utils first.

It’s a feature of GNU tar. I don’t know about competing implementations, but GNU tar should be the most relevant to ubuntu. gnu.org/software/tar/manual/tar.html#SEC131

if you run into tar: xz: Cannot exec: No such file or directory , install xz-utils : sudo apt-get install xz-utils

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’

@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.

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

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: That’s probably why it doesn’t make you specify the compression format flag anymore. (See ramslök’s answer.)

This should totally be the accepted answer since it answers the question for any version of tar supporting .xz

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

Then use tar to untar the file.

At least on my Ubuntu machine, unxz is not equivalent to xz -dc , but to xz -d . So to extract file.tar.xz to file.tar , you’d simply write unxz file.tar.xz . If you want an equivalent to xz -dc , decompressing to stdout, use xzcat . For example xzcat file.tar.xz | tar x .

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

@MarkJeronimus I don’t find this so good since it creates an intermediate file. Using GNU tar or a pipe should demand less resources.

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 

-v — verbosely list files processed

Читайте также:  Regex in sed linux

-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:

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:

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

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 - 

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.

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.

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[1]);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[1] ) 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 extractall() function.

Источник

How to Extract (Unzip) tar.xz File

The tar command allows you to create and extract tar archives. It supports a vast range of compression programs such as gzip, bzip2, lzip, lzma, lzop, xz and compress.

Xz is a popular algorithm for compressing files based on the LZMA algorithm. By convention, the name of a tar archive compressed with xz ends with either .tar.xz or .txz.

This article explains how to use the tar command to extract (or unzip) .tar.xz or .txz archives.

Extracting tar.xz File #

The tar utility is pre-installed by default on all Linux distributions and macOS.

To extract a tar.xz file, invoke the tar command with the —extract ( -x ) option and specify the archive file name after the -f option:

tar auto-detects compression type and extracts the archive. The same command can be used to extract tar archives compressed with other algorithms, such as .tar.gz or .tar.bz2 .

If the command-line is not your thing, you can use the GUI File manager. To extract (unzip) a tar.xz file simply right-click the file you want to extract and select “Extract”. Windows users need a tool named 7zip to extract tar.xz files.

Читайте также:  Линукс узнать какие порты открыты

For more verbose output, use the -v option. This option tells tar to display the names of the files being extracted on the terminal.

By default, tar extracts the archive contents in the current working directory . To extract archive files in a specific directory, use the —directory ( -C ).

The following example shows how to extract the archive contents to the /home/linuxize/files directory:

tar -xf archive.tar.xz -C /home/linuxize/files

Extracting Specific Files from a tar.xz File #

To extract a specific file(s) from a tar.xz file, append a space-separated list of file names to be extracted after the archive name:

tar -xf archive.tar.xz file1 file2

When extracting files, you must provide their exact names including the path, as printed when the tar is invoked with the —list ( -t ) option.

Extracting one or more directories from an archive is the same as extracting multiple files:

tar -xf archive.tar.xz dir1 dir2

If you try to extract a file that doesn’t exist in the archive, an error message similar to the following will be shown:

tar -xf archive.tar.xz README
tar: README: Not found in archive tar: Exiting with failure status due to previous errors 

The —wildcards option allows you to extract files from a tar.xz file based on a wildcard pattern. The pattern must be quoted to prevent the shell from interpreting it.

For example, to extract only the files whose names end in .png , you would use:

tar -xf archive.tar.xz --wildcards '*.png'

Extracting tar.xz File from stdin #

When extracting a compressed tar.xz file by reading the archive from standard input (usually through piping), you must specify the decompression option. The -J option tells tar that the file is compressed with xz.

In the example below we are downloading the Linux kernel using the wget command and pipe its output to the tar command:

wget -c https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.3.tar.xz -O - | sudo tar -xj

If you don’t specify a decompression option, tar will show you which option you should use:

tar: Archive is compressed. Use -J option tar: Error is not recoverable: exiting now 

Listing tar.xz File Content #

To list the content of a tar.xz file, use the —list ( -t ) option:

The output will look something like this:

If you add the —verbose ( -v ) option, tar will print more information, such as owner, file size, timestamp ..etc:

-rw-r--r-- linuxize/users 0 2020-02-15 01:19 file1 -rw-r--r-- linuxize/users 0 2020-02-15 01:19 file2 -rw-r--r-- linuxize/users 0 2020-02-15 01:19 file3 

Conclusion #

tar.xz file is a Tar archive compressed with xz. To extract a tar.xz file, use the tar -xf command, followed by the archive name.

If you have any questions, please leave a comment below.

Источник

How to Extract Tar.xz File on Linux Command Line

How to Extract Tar.xz File on Linux Command Line

LinuxStoney

Today we learn in this tutorial how to extract (Unzip) Tar.xz Tar.gz File on Linux Command Line Command tar allows you to create and extract archives with tar format. This command also supports various compression programs such as gzip, bzip2, lzip, lzma, lzop, xz and compress.

Xz is a popular algorithm for compressing files based on the LZMA algorithm. By convention, the name of a tar archive compressed with xz ends with .tar.xz or .txz .

In this tutorial, we will explain how to extract (or unzip) .tar.xz and archives .txz .

How to extract tar.xz . file

Most Linux and macOS distributions come with the tar utility installed by default.

Читайте также:  Play on linux ubuntu установка

To extract the tar.xz file, Use the command tar with options —extract ( -x ) and specify the archive file name after the option -f :

The command tar automatically detects the compression type and extracts the archive. The same command can be used to extract tar archives compressed with other algorithms, such as .tar.gz or tar.bz2

If you are a Desktop user and still afraid to use the terminal/command line, you can use your File Manager. To extract (unzip) the tar.bz2 file simply right-click the file you want to extract and select “Extract”. Windows users will need a tool called 7zip to extract the tar.xz file.

For more verbose output use options -v . This option tells tar to display the name of the file being extracted in the terminal.

By default, tar will extract the contents of the archive in the current working directory . Use —directory ( -C ) to extract archive files in a specific directory:

For example, to extract the contents of an archive to a directory /home/budi/files , you must type:

tar -xf archive.tar.xz -C / home / budi / files

Extract Specific Files from Tar.xz File File

To extract specific files from the tar.bz2 file, add a list of separated filenames. For example, we want to extract foto201.jpg and foto202.jpg

tar -xf archive.tar.xz foto201.jpg foto202.jpg

When extracting files, you must provide the exact name, including the path, as printed when option —list ( -t ) is used.

Extracting one or more directories from an archive is equivalent to extracting multiple files

tar -xf archive.tar.xz dir1 dir2

If you try to extract a file that is not in the archive, an error message similar to the following will be displayed:

tar -xf archive.tar.xz README
tar: README: Not found in archive tar: Exiting with failure status due to previous errors

Option —wildcards allows you to extract files from tar.xz files based on wildcard patterns. The pattern must be quoted to prevent the shell from interpreting it differently.

For example, to extract only files whose names end in .png (image file), you would use:

tar -xf archive.tar.xz --wildcards '*.png'

Extract the tar.xz file from stdin

When extracting a compressed tar.bz2 file by reading the archive from standard input (usually via piping), you must specify a decompression option. Option -J will tell tar that the file is compressed with xz.

In the example below, we will download the Linux kernel using the command wget and send the result to command tar :

wget -c https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.3.tar.xz -O - | sudo tar -xj

If you do not specify an option to decompress, tar will show you which option you should use:

tar: Archive is compressed. Use -J option tar: Error is not recoverable: exiting now

Create a List of tar.xz files

To list the contents of the tar.xz file, use the options —list ( -t ):

The output will look like this:

If you add options —verbose ( -v ), tar will print more information, such as owner, file size, timestamp, etc :

-rw-r - r-- linuxid / users 0 2020-02-15 01:19 file1 -rw-r - r-- linuxid / users 0 2020-02-15 01:19 file2 -rw-r - r-- linuxid / users 0 2020-02-15 01:19 file3

Conclusion

In this tutorial we learned How to Extract Tar.xz File on Linux Command Line, The tar.xz file is a Tar archive compressed with xz. To extract the tar.xz file, use the command tar -jf followed by the file name.

Источник

Оцените статью
Adblock
detector