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.
- Files & directories
- Last checked
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.gztar xf archive.tar.xztar 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 /etctar -czf backup.tar.gz /etc
To look inside without extracting, use tar tf archive.tar.xz. It detects the format too.
Learn more
- How to Unpack .xz and tar.xz Files: A Simple Guide Full guide · Updated Apr 2025
-
tarcommand cheat sheet Options and copy-ready examples
