Introduction
XZ is a lossless data compression algorithm that has a better compression ratio and lower decompression time, but uses more memory.
XZ Compression steps
We can use tar and pipe the output to xz. This will allow us to use xz options, like --extreme.
tar cf - directory | xz -e > directory.tar.xz
If you want to use low amount of memory you could try the option 4e for the xz which uses less memory, but it will be slower than the default.
If you don't want to pipe to xz a one command alternative is possible. We are going to tar directly with the J, which means to use xz (instead -j- which means bzip).
tar cJf directory.tar.xz directory
XZ Decompression steps
For decompression using the tar command in the latest versions of linux it is only neccesary to use the xf parameters, tar will detect compression algorithm.
tar xf compressed_file.tar.xz