How to compress/decompress LZMA/LZMA2 files in Linux

This post is complementary of a three years old post in which explanation about .xz file extension missing.

LZMA/LZMA2 compression algorithms usually identifiable by .xz extension. In Linux several tools are available to support .xz files. The most famous one is tar. tar is indeed a multi-purpose tool that supports different compression algorithms including gzip, bzip2, LZMA, etc. To be able to work with .xz files however, you first need to install xz-utils. In Ubuntu you can install using apt-get command.

$ sudo apt-get install xz-utils

To compress files use tar command like following,

$ tar -cvJf <dot.tar.xz> <files/folders>

To extract contents of a .xz file run,

$ tar -xvJf <dot.tar.xz>

Besides tar you may want to use xz command. Usage is identical except xz command does not support .tar.xz. It supports only .xz extension.

To compress,

$ xz -db <dot.xz>

For extraction,

$ xz -zv <dot.xz> <file(s)>

Leave a Reply