How to Create and Extract Zstandard Tar Archives in Linux Terminal Using tar and zstd

For decades, Linux administrators and developers relied on gzip (.tar.gz) and xz (.tar.xz) for archiving directory trees and backing up servers. While gzip compresses quickly with modest compression ratios and xz delivers high compression at the cost of slow CPU execution, neither algorithm was designed for modern multi-core processors. Meta’s Zstandard (zstd) algorithm provides an optimal balance, delivering compression ratios comparable to xz while matching or exceeding the decompression speed of uncompressed storage. Using GNU tar with native zstd integration allows you to create lightning-fast, multi-threaded .tar.zst archives directly from the command line.

Advantages of Zstandard (zstd) over Gzip and XZ

Zstandard was engineered to eliminate traditional compression trade-offs:

  • Extreme Decompression Speed: Regardless of the compression level chosen (from level 1 to level 19), zstd decompresses at near-memory bus speeds (often exceeding 1 GB/s per core), significantly speeding up software deployments and container image unpacking.
  • Scalable Compression Levels: Offers 19 standard compression levels. Levels 1–3 provide ultra-fast real-time archiving, while levels 15–19 provide compression density approaching xz.
  • Native Multi-Threading: Supports multi-threaded processing out of the box, allowing compression workloads to scale across all available CPU cores.
  • Native GNU tar Support: Modern distributions (including Ubuntu, Debian, Fedora, and Arch) bundle GNU tar version 1.31 or newer, which features native --zstd flag recognition.

Installing the zstd Utility on Linux

Before GNU tar can invoke the Zstandard compression engine, verify that the zstd binary is installed on your operating system:

  1. On Ubuntu and Debian systems:
    sudo apt update && sudo apt install zstd
  2. On Fedora, RHEL, and CentOS Stream:
    sudo dnf install zstd
  3. On Arch Linux:
    sudo pacman -S zstd

Creating a .tar.zst Archive Using Native tar Syntax

To archive and compress a directory into a Zstandard tarball:

  1. Open your terminal and navigate to the directory containing your project or backup files.
  2. Execute the archiving command using the --zstd flag:
    tar --zstd -cf backup.tar.zst /path/to/source_directory
  3. Alternatively, use short flag notation (-I zstd):
    tar -I zstd -cf project_files.tar.zst ./my_project
  4. To display progress and list files as they are archived, include the verbose flag (-v):
    tar --zstd -cvf site_backup.tar.zst /var/www/html

Leveraging Multi-Core Multi-Threading and Custom Compression Levels

By default, basic zstd invocation uses a single CPU core at compression level 3. To harness all CPU cores and select custom compression strength, pass options to zstd via the -I (use-compress-program) flag:

  1. To compress using all available CPU threads (-T0) at standard level 3:
    tar -I 'zstd -T0' -cf multi_threaded_backup.tar.zst ./data_folder
  2. To achieve maximum compression density for archival storage (level 19) across all CPU threads:
    tar -I 'zstd -19 -T0' -cf cold_storage_archive.tar.zst ./database_dumps
  3. For ultra-fast real-time archiving where speed is the primary objective:
    tar -I 'zstd -1 -T0' -cf fast_snapshot.tar.zst ./build_artifacts

Listing Archive Contents Without Extracting

To inspect the file list inside a .tar.zst archive without unpacking files to disk:

tar --zstd -tf backup.tar.zst

You can pipe this output into grep or less to verify specific file paths before extraction.

Extracting a .tar.zst Archive

To unpack a Zstandard compressed tarball:

  1. Extract into the current directory:
    tar --zstd -xf backup.tar.zst
  2. To extract files into a specific target destination directory:
    tar --zstd -xf backup.tar.zst -C /opt/extracted_data/
  3. GNU tar automatically detects the .zst file signature on modern builds, so simply running tar -xf backup.tar.zst also works seamlessly across modern Linux distributions.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.