How to extract .xz file in Linux?


The xz is a lossless data compression file format based on lzma compression that uses a file extension .xz. In most cases, it achieves a higher compression rate than other alternatives such as gzip and bzip2.

The xz is a part of the XZ utils package, which itself consists of software and command-line compression and decompression tools like lzma, xz, etc.

In this article, I will discuss how to extract a .xz file in Linux.

Install XZ utils in Linux

If you want to compress a file in xz file format or want to decompress it then make sure you have the XZ utils package installed on your Linux system. If it is not on your system you can use one of the commands to install it –

In Ubuntu/Linux Mint/ Debian use –

sudo apt install xz-utils -y

To install in Fedora use –

sudo dnf install xz-utils -y

How to extract a file with .xz format

Once the installation is completed you can extract the .xz file by using the given command –

unxz file.xz

OR use --decompress option with xz command –

xz --decompress file.xz

You can find the detailed list of options that can be used with the unxz command on its man page –

man unxz

How to extract .tar.xz file

Now suppose you have a file with .tar.xz extension then you need to use the tar command with certain options to extract it as it is given below.

tar -xf file.tar.xz

Where

-x – Use to extract a file

-f – Need to specify the name of the file after using this option

The tar will automatically detect the compression type and extract the file.

If you want to extract specific files from the .tar.xz file then use the command given below.

tar -xf file.tar.xz file1 file2

Note:- Don’t forget to remove file.xz or file.tar.xz with the actual file name.

Now to see more options that can be used with tar command in its man page.

man tar

Conclusion

I hope now you are able to extract a file that has a .xz or .tar.xz extension in a Linux system. For any query write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.