Zstandard, often abbreviated as zstd, is a relatively new compression tool that premiered in 2015. It was created by engineers at Facebook, looking to improve on the speed and compression ratio of longstanding tools like gzip. It's quickly becoming a standard compression tool on many Linux distros, so now's a perfect time to learn about using it.

In this guide, we'll go over the instructions to install and use zstd on Linux, with command line examples that show you how to compress files as well as open archives that use zstd.

In this tutorial you will learn:
  • How to install Zstandard on major Linux distros
  • How to use Zstandard through command line examples
Compressing a file with zstd on Linux
Compressing a file with zstd on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Zstandard (zstd)
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

How to install Zstandard on major Linux distros

Zstandard isn't included by default on every Linux distribution. If your system doesn't already have it installed, use the appropriate command below to install it.

To install Zstandard on Ubuntu, Debian, and Linux Mint:

$ sudo apt install zstd

To install Zstandard on CentOS, Fedora, AlmaLinux, and Red Hat:

$ sudo dnf install zstd

SUBSCRIBE NEWSLETTER & RSS
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


To install Zstandard on Arch Linux and Manjaro:

$ sudo pacman -S zstd

Zstandard command line examples

It's easiest to learn about zstd through examples. To get started, use some of the following commands on your own system, and you'll quickly have it mastered.

  1. To use zstd in its simplest form, with all default options, execute the zstd command and specify the name of the file you want to compress. This will make a new copy of the file, but compressed and with the .zst extension.
    $ zstd example1.txt
    
  2. You can compress multiple files at the same time by specifying each one with a space in between them, or by using wildcards in your command.
    $ zstd example1.txt example2.txt example3.txt
    OR
    $ zstd example*.txt
    
  3. To decompress a zstd archive, use the -d option.
    $ zstd -d example1.txt.zst
    OR
    $ unzstd example1.txt.zst
    


  4. You can use different levels of compression with zstd. If you're concerned about speed, you can specify the following option to trade some compression ratio in exchange for increased speed.
    $ zstd --fast example1.txt
    
  5. On the other end of the spectrum, we can instruct zstd to use higher compression, which will also make the process last a little longer. Zstandard's default compression level is 3. The --fast swtich drops the compression level to 1. We can specify any compression level, all the way up to 19, with the following syntax (here we are using 15).
    $ zstd -15 example1.txt
    
  6. The --ultra option will unlock Zstandard's absolute highest compression levels - all the way up to 22. Here's how you'd use it.
    $ zstd --ultra -22 example1.txt
    
  7. Just like gzip, xz, and other compression tools, we'll need to use a tar command to compress multiple files or directories with zstd. Use the following syntax to compress a directory.
    $ tar --zstd -cf example.tar.zst example/
    
  8. We could also use tar's -I option. The advantage of this method is that it allows us to specify extra parameters with our zstd command. For example, this command uses the --ultra option mentioned in a previous example, so we can unlock the maximum compression level for our directory.
    $ tar -I 'zstd --ultra -22' -cf example.tar.zst example/
    
  9. Use the -v (verbose) option to see detailed output about zstd's progress as it compresses your file(s).
    $ zstd -v example1.txt
    AND
    $ tar -I 'zstd -v' -cvf example.tar.zst example/
    


  10. To decompress a tar archive with the .tar.zst file extension, use the following command syntax.
    $ tar -I zstd -xvf example.tar.zst
    

Closing Thoughts

In this guide, we saw how to install and use the Zstandard (zstd) compression tool in Linux. We learned how to compress and decompress individual files as well as directories, with various levels of compression. The examples shown in this guide should be enough for you to get the most out of zstd on your own system. If you'd like to learn about some of its other options, we recommend reading the manual page with man zstd.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.