Some software seems to be distributed in a new archive format:
$ file node-v18.7.0-linux-x64.tar.xz
node-v18.7.0-linux-x64.tar.xz: XZ compressed data
How do I extract this, preferably using tar (like I can with gzip or bzip2) ?
Several tar
implementations (at least GNU tar
¹, star
and libarchive's bsdtar
) already handle this compression format, you can either:
Don't explicitly specify a format and let tar detect the compression automatically (with either gtar², bsdtar or star³):
tar -xf node-v18.7.0-linux-x64.tar.xz
Or if you like to watch the progress:
tar -xvf node-v18.7.0-linux-x64.tar.xz
Use -J
/--xz
with GNU's or libarchive's or -xz
with star
to tell tar
to expect XZ
tar -xJf node-v18.7.0-linux-x64.tar.xz
gtar -xJf node-v18.7.0-linux-x64.tar.xz
bsdtar -xJf node-v18.7.0-linux-x64.tar.xz
star -x -xz -f node-v18.7.0-linux-x64.tar.xz
Without those specific tar
implementations or with the standard pax
command (tar
has been removed from the UNIX standard as there were too many incompatibilities between implementations), decompress the archive with xz
⁴ and then unpack the archive via a pipe:
xz -dc node-v18.7.0-linux-x64.tar.xz | tar -xvf -
xz -dc node-v18.7.0-linux-x64.tar.xz | pax -rv
¹ generally called tar
on GNU systems, but often gtar
or gnutar
or gnu-tar
on other systems if installed there beside the system's one.
² with GNU tar, that doesn't work if the file is passed on stdin with -
as the file name or if the file is no seekable in which case you need to pass the -J
option.
³ with star, that doesn't work if the file is not seekable in which case you do need to use the -xz
option. tar -xf -
still works as long as stdin is seekable.
⁴ beware failures of xz
may not always be detected in that case. Most Bourne-like shells now support the pipefail
option from ksh93 which can help here; set with set -o pipefail
.
tar
has supportedxz
archives since March 2009.