I've come across XZ files more than once, most recently when downloading Kali Linux. It should be a fairly common knowledge now, but some operating systems still don't support is – so I decided to research and to document it.
What is XZ file?
XZ is a modern lossless compression algorithm, it's more efficient that gzip and bzip2. Apparently, many Linux distros are using XZ for compressing their software packages or ISO images. XZ is an open-source format maintained via Tukaani Project – XZ.
Support for XZ in tar
Modern Linux distros (certainly Ubuntu 19.x and CentOS 7.x when I checked today) have xz utils package installed, which allows tar command to automatically unpack XZ files.
If xz-utils didn't come preinstalled, you can install it like this in Ubuntu/Debian:
# apt install xz-utils
or like this in CentOS/Fedora/RedHat:
# yum install xz
gzip/gunzip Support for XZ in macOS
Although tar in macOS doesn't support XZ format natively:
greys@mcfly:~/Downloads $ tar xzvf kali-linux-2020.1-rpi3-nexmon-64.img.xz
tar: Error opening archive: Unrecognized archive format
… you can still use gunzip to decompress the XZ file in macOS:
greys@mcfly:~/Downloads $ ls -al kali-linux-2020* -rw-r--r--@ 1 greys staff 259647 30 Jan 22:57 kali-linux-2020-1.png -rw-r--r--@ 1 greys staff 1048328860 30 Jan 23:06 kali-linux-2020.1-rpi3-nexmon-64.img.xz greys@mcfly:~/Downloads $ gunzip kali-linux-2020.1-rpi3-nexmon-64.img.xz greys@mcfly:~/Downloads $ ls -ald kali-linux-2020.1-rpi3-nexmon-64.img -rw-r--r-- 1 greys staff 6999999488 30 Jan 23:06 kali-linux-2020.1-rpi3-nexmon-64.img
xz-utils in macOS
If you insist on managing XZ files using xz utils, you'll need to install them with brew:
… and then a whole bunch of XZ commands becomes available:
xz xzcat xzcmp xzdec xzdiff xzegrep xzfgrep xzgrep xzless xzmore