Skip to content
Latchkey

tar -J: xz Compression (Usage & CI Errors)

tar -J pipes the archive through xz for the smallest common tarballs.

xz gives the best ratio of the classic three and is the default for many source releases. The catch is the flag is uppercase J; lowercase j is bzip2.

What it does

tar -J (uppercase) runs the archive through xz on create and unxz on extract, producing or reading a .tar.xz (also .txz). It usually compresses smallest but is the slowest and most memory-hungry, so it suits release artifacts more than fast inner-loop caches.

Common usage

Terminal
tar -cJf out.tar.xz dir/
tar -xJf out.tar.xz
tar -xf out.tar.xz           # auto-detect on GNU/BSD
XZ_OPT=-9 tar -cJf out.tar.xz dir/   # max compression

Options

FlagWhat it does
-J / --xzFilter through xz/unxz (uppercase J)
-j / --bzip2NOT xz: this is bzip2 (common mix-up)
XZ_OPT env varPass flags to xz, e.g. XZ_OPT=-9 or -T0 for threads
-I "xz -T0"Custom compressor program with options (GNU)

Common errors in CI

A frequent slip is case: tar -cjf out.tar.xz dir uses bzip2, not xz, producing a misnamed file. tar (child): xz: Cannot exec: No such file or directory means xz is not installed; add the xz-utils package. xz: (stdin): File format not recognized on extract means the file is not xz; drop -J and auto-detect or use the correct flag.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →