Skip to content

Did you know?

tar xf extracts .tar.gz, .tar.xz, .tar.bz2 and .tar.zst files without a compression flag.

GNU tar detects the format itself; you only need -z, -J or -j when creating.

Explained

Remembering whether it is -z, -j or -J for each format isn’t necessary when you extract. GNU tar, the default on Linux, looks at the archive and picks the right decompressor:

tar xf archive.tar.gz
tar xf archive.tar.xz
tar xf archive.tar.zst

The decompression program still has to be installed: xz for .xz files, zstd for .zst. Add -v to see the file names and -C /path to extract somewhere else.

When you create an archive, tar needs to be told. Either use the flag, or let -a choose the compression from the file name:

tar -caf backup.tar.zst /etc
tar -czf backup.tar.gz /etc

To look inside without extracting, use tar tf archive.tar.xz. It detects the format too.

Learn more

← All tech tips · Suggest a fix

Back to top