Home/Engineer/OS / Systems/Linux Extraction Commands: t…
OS / SystemsBeginnerUbuntuDebianCentOSmacOStargzipzip

Linux Extraction Commands: tar.gz, tar.zst, zst, zip, and 7z

A per-extension reference for extracting tar.gz, tar.zst, and standalone zst archives. Covers tar xzf options, keeping originals, missing or unsupported zstd errors, and how to choose a format.

Contents
  1. Extraction commands by extension
  2. Compression format comparison
  3. Using tar
  4. Using gzip / gunzip
  5. Using zip / unzip
  6. Using 7-Zip (7z)
  7. Using Zstandard (Zstd)
  8. tar vs zip vs 7z vs zstd — when to use which
  9. Extracting Zstandard (.zst, .tar.zst) — common problems FAQ
  10. Practical patterns
  11. What tar xzf means and common mistakes

On Linux, extract .tar.zst with tar --zstd -xf archive.tar.zst and a standalone .zst with zstd -d file.zst. For .tar.gz, use tar -xzf archive.tar.gz. Even when extensions look similar, distinguish a tar archive that bundles multiple files from a single compressed file.

Extraction commands by extension

The tar examples below assume GNU tar, and each compressor must be installed. Create the destination directory first; for a newly received file, list its contents, then extract into an empty working directory.

ExtensionList contentsExtract
.tartar -tf archive.tartar -xf archive.tar
.tar.gz, .tgztar -tzf archive.tar.gztar -xzf archive.tar.gz
.tar.bz2tar -tjf archive.tar.bz2tar -xjf archive.tar.bz2
.tar.xztar -tJf archive.tar.xztar -xJf archive.tar.xz
.tar.zsttar --zstd -tf archive.tar.zsttar --zstd -xf archive.tar.zst
standalone .zstIntegrity check with zstd -t file.zstzstd -d file.zst
.zipunzip -l archive.zipunzip archive.zip -d extracted
.7z7z l archive.7z7z x archive.7z -oextracted

GNU tar's compression options and zstd's single-file handling are also distinguished in the official manuals. GNU tar compression formats, zstd CLI manual

Compression format comparison

Compression ratio and speed vary with the data and options; the table below shows typical tendencies to help you choose.

FormatExtensionRatioSpeedTypical use
gzip.tar.gz / .tgzMediumFastTypical Linux distros, backups
bzip2.tar.bz2HighSlowSource code and large datasets
xz.tar.xzVery highVery slowKernel and OS packages
zip.zipMediumFastCross-platform file sharing
7-Zip.7zVery highSlowData that needs maximum compression
Zstandard (Zstd).tar.zstHighVery fastModern distros, Docker images

Using tar

Creating archives

  • Compress with gzip: tar czf archive.tar.gz /path/to/dir
  • Compress with bzip2: tar cjf archive.tar.bz2 /path/to/dir
  • Compress with xz: tar cJf archive.tar.xz /path/to/dir
  • Compress with Zstd: tar --zstd -cf archive.tar.zst /path/to/dir

Show progress

Bash
tar czf archive.tar.gz -v /path/to/dir

Exclude or include specific files

  • Exclude specific files:
    Bash
    tar czf archive.tar.gz --exclude='*.log' --exclude='.git' /path/to/dir
  • Include only specific files:
    Bash
    tar czf archive.tar.gz file1.txt file2.txt dir/

Extracting archives

  • Extract with automatic format detection: tar xf archive.tar.gz
  • Extract into a directory:
    Bash
    tar xzf archive.tar.gz -C /target/dir
  • List contents without extracting: tar tzf archive.tar.gz
  • Extract a specific file: tar xzf archive.tar.gz path/to/specific/file

tar option summary

OptionMeaning
cCreate: make an archive
xExtract: unpack an archive
tList: show contents
zUse gzip
jUse bzip2
JUse xz
fSpecify filename
vVerbose progress
CDestination directory

Using gzip / gunzip

By default, gzip file.txt replaces the original with the compressed file. To keep the original, use -k or the stdout option -c. GNU gzip manual

Bash
# Compress a single file (on success, replaces the original with .gz)
gzip file.txt            # → file.txt.gz

# Keep original (-k)
gzip -k file.txt

# Decompress
gunzip file.txt.gz       # or gzip -d file.txt.gz

# Compression level (1=fast, 9=max)
gzip -9 file.txt

# Compress multiple files
gzip *.log

Using zip / unzip

Bash
# Compress files
zip archive.zip file1 file2

# Recursively compress a directory
zip -r archive.zip /path/to/dir

# Exclude specific files
zip -r archive.zip . -x "*.log" -x ".git/*"

# Set a password
zip -er archive.zip files/

# Extract
unzip archive.zip

# Extract into a directory
unzip archive.zip -d /target/dir

# List contents
unzip -l archive.zip

Using 7-Zip (7z)

Bash
# Install the 7-Zip package from your distro's repository.
# On distros where the binary is named 7zz, replace 7z with 7zz below.
command -v 7z || command -v 7zz

# Compress
7z a archive.7z /path/to/dir

# Maximum compression (-mx=9)
7z a -mx=9 archive.7z /path/to/dir

# Set a password
7z a -p archive.7z files/

# Extract
7z x archive.7z -o/target/dir

# List contents
7z l archive.7z

Using Zstandard (Zstd)

Bash
sudo apt install -y zstd        # Debian/Ubuntu
sudo dnf install -y zstd        # RHEL/Fedora

# Extract tar.zst (extract; GNU tar 1.31+, zstd required)
tar --zstd -xf archive.tar.zst

# Extract into a directory
tar --zstd -xf archive.tar.zst -C /target/dir

# Create tar.zst
tar --zstd -cf archive.tar.zst /path/to/dir

# Compress and decompress a single file
zstd file.log            # → file.log.zst
zstd -d file.log.zst     # decompress (= unzstd)

# High compression (-19) + multithreading (-T0)
tar -cf backup.tar.zst -I 'zstd -19 -T0' /data

# Use zstd with tar 1.30 or older
zstd -dc archive.tar.zst | tar -xf -

tar vs zip vs 7z vs zstd — when to use which

  • tar: Not compression by itself—an archiver that "bundles many files into one." Combine it with gzip/bzip2/xz/zstd to compress. The Linux/Unix default when you need to preserve permissions and symbolic links.
  • zip: When exchanging files with Windows or Mac users. Medium ratio and speed, but opens on most OSes with no extra install (cross-platform compatibility first).
  • 7z: When compression ratio matters most (e.g. distribution archives, long-term backups) and slower compress/extract is acceptable.
  • zstd (.tar.zst): Tune speed vs. size for recurring backups and build artifacts. Confirm the receiving environment supports zstd. For repeated jobs, benchmark gzip vs. zstd on your actual data.
SituationRecommended format
Sending files to Windows userszip
Maximum compression (size first)7z or xz
Fast recurring backups / CI artifactszstd (.tar.zst)
Linux archives that preserve permissions/linkstar (+ gzip/zstd)
Kernel / package distributionxz

Extracting Zstandard (.zst, .tar.zst) — common problems FAQ

Q. How do I extract a .zst file? Install the zstd package.

Bash
# Install
sudo apt install -y zstd    # Debian/Ubuntu
sudo dnf install -y zstd    # RHEL/Fedora

# Extract a standalone .zst file
unzstd file.log.zst
# or
zstd -d file.log.zst

Q. How do I open a .tar.zst file? On GNU tar 1.31 or later, if the zstd binary is installed, extract directly with --zstd.

Bash
tar --zstd -xf archive.tar.zst
tar --zstd -xf archive.tar.zst -C /target/dir   # extract into a directory

Q. I get tar: Unrecognized archive format or a --zstd option error. First check the implementation, install, and file integrity with tar --version, command -v zstd, and zstd -t archive.tar.zst. Unsupported --zstd, a missing zstd binary, and a corrupted file are different problems. If your tar has no --zstd, pipe zstd output into tar.

Bash
zstd -dc archive.tar.zst | tar -xf -
# Check tar version
tar --version

Q. Which is faster: tar.zst or zip/7z? It depends on the data, compression level, thread count, and CPU. Rather than assuming a fixed multiplier, measure time and output size on your actual backup data. For automated pipelines that compress/extract repeatedly (CI, backup scripts), zstd is usually the better fit.

Q. What does tar czf mean? It combines c (create) + z (gzip) + f (filename). To compress with zstd, use --zstd instead of z: tar --zstd -cf archive.tar.zst /path.

Practical patterns

Bash
# Daily backup of a log directory
tar czf /backup/logs-$(date +%Y%m%d).tar.gz /var/log/myapp/

# Check archive size
ls -lh archive.tar.gz

# Stream a compressed archive to a remote server
tar czf - /data | ssh user@remote "cat > /backup/data.tar.gz"

# Split archive (4GB chunks)
tar czf - /large-data | split -b 4G - backup.tar.gz.part

What tar xzf means and common mistakes

x is extract, z is gzip, f specifies the archive file. Do not add z for .tar.zst—use --zstd. -C is the extract destination and must already exist.

Bash
mkdir -p extracted
tar --zstd -tf archive.tar.zst
tar --zstd -xf archive.tar.zst -C extracted

Getting a single file after extracting .zst can be expected. zstd itself does not bundle multiple files the way tar does. Renaming the extension also does not change the compression format.

To compress and retain log files on a schedule, see the logrotate configuration and log rotation guide in addition to one-off tar jobs.

#tar#gzip#zip#7z#linux
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Topic-related official docs (auto-linked · not per-claim sources)Linux man pages ↗

Questions & answers

Ask a question about this guide. We'll review and reply.