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.
| Extension | List contents | Extract |
|---|---|---|
.tar | tar -tf archive.tar | tar -xf archive.tar |
.tar.gz, .tgz | tar -tzf archive.tar.gz | tar -xzf archive.tar.gz |
.tar.bz2 | tar -tjf archive.tar.bz2 | tar -xjf archive.tar.bz2 |
.tar.xz | tar -tJf archive.tar.xz | tar -xJf archive.tar.xz |
.tar.zst | tar --zstd -tf archive.tar.zst | tar --zstd -xf archive.tar.zst |
standalone .zst | Integrity check with zstd -t file.zst | zstd -d file.zst |
.zip | unzip -l archive.zip | unzip archive.zip -d extracted |
.7z | 7z l archive.7z | 7z 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.
| Format | Extension | Ratio | Speed | Typical use |
|---|---|---|---|---|
| gzip | .tar.gz / .tgz | Medium | Fast | Typical Linux distros, backups |
| bzip2 | .tar.bz2 | High | Slow | Source code and large datasets |
| xz | .tar.xz | Very high | Very slow | Kernel and OS packages |
| zip | .zip | Medium | Fast | Cross-platform file sharing |
| 7-Zip | .7z | Very high | Slow | Data that needs maximum compression |
| Zstandard (Zstd) | .tar.zst | High | Very fast | Modern 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
tar czf archive.tar.gz -v /path/to/dirExclude 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
| Option | Meaning |
|---|---|
| c | Create: make an archive |
| x | Extract: unpack an archive |
| t | List: show contents |
| z | Use gzip |
| j | Use bzip2 |
| J | Use xz |
| f | Specify filename |
| v | Verbose progress |
| C | Destination 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
# 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 *.logUsing zip / unzip
# 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.zipUsing 7-Zip (7z)
# 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.7zUsing Zstandard (Zstd)
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.
| Situation | Recommended format |
|---|---|
| Sending files to Windows users | zip |
| Maximum compression (size first) | 7z or xz |
| Fast recurring backups / CI artifacts | zstd (.tar.zst) |
| Linux archives that preserve permissions/links | tar (+ gzip/zstd) |
| Kernel / package distribution | xz |
Extracting Zstandard (.zst, .tar.zst) — common problems FAQ
Q. How do I extract a .zst file?
Install the zstd package.
# 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.zstQ. 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.
tar --zstd -xf archive.tar.zst
tar --zstd -xf archive.tar.zst -C /target/dir # extract into a directoryQ. 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.
zstd -dc archive.tar.zst | tar -xf -
# Check tar version
tar --versionQ. 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
# 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.partWhat 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.
mkdir -p extracted
tar --zstd -tf archive.tar.zst
tar --zstd -xf archive.tar.zst -C extractedGetting 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.
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
Questions & answers
Ask a question about this guide. We'll review and reply.