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 tutorial you will learn:
- How to install Zstandard on major Linux distros
- How to use Zstandard through command line examples
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – 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.
$ sudo apt install zstd
$ sudo dnf install zstd
$ 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.
- To use zstd in its simplest form, with all default options, execute the
zstdcommand 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
$ zstd example1.txt
- 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
- To decompress a zstd archive, use the
$ zstd -d example1.txt.zst OR $ unzstd example1.txt.zst
- 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
- 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
--fastswtich 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
--ultraoption 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
- Just like gzip, xz, and other compression tools, we’ll need to use a
tarcommand to compress multiple files or directories with zstd. Use the following syntax to compress a directory.
$ tar --zstd -cf example.tar.zst example/
- We could also use tar’s
-Ioption. The advantage of this method is that it allows us to specify extra parameters with our
zstdcommand. For example, this command uses the
--ultraoption 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/
- 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/
- To decompress a tar archive with the
.tar.zstfile extension, use the following command syntax.
$ tar -I zstd -xvf example.tar.zst
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