Although there are many graphical and command-line data compression tools, zstd is the one that stands out. Short for Zstandard, zstd is a data compression tool developed by Facebook data engineers in 2015. It is so effective and easy to use, that zstd has become the go-to compression tool for many Linux users. This tutorial will show you how to install zstd and use it from the terminal.
How to Install zstd on Various Linux distros
Before you can use zstd, you need to install it – if you don’t have it already installed on your Linux distro.
Fortunately, installing zstd is as simple as executing a couple of commands.
Note: based on which Linux distro you’re running, you may have to install dependencies and various tools before compiling and installing zstd. That’s why the first thing you should do is update your system. For Debian and Ubuntu-based distro, you can use the update and upgrade commands:
sudo apt update sudo apt upgrade
To ensure that you have all the dependencies that zstd needs, install
tar using the command:
sudo apt install build-essential wget tar
Now that you have the all the required dependencies and tools installed, you can move on and install zstd.
On Debian/Ubuntu/Linux Mint
To install zstd on a Debian/Ubuntu/Linux Mint system, execute the command:
sudo apt install zstd
On Fedora/Red Hat/CentOS/AlmaLinux
To install Zstandard on Fedora/Red Hat/CentOS/AlmaLinux systems, execute the command;
sudo dnf install zstd
On Arch Linux/Manjaro
To install zstd on Arch Linux/Manjaro systems, execute the command:
sudo pacman -S zstd
Now that we have zstd installed and ready to go, we can start using it to compress files.
Compressing Files with zstd
Using zstd to compress a file is easy. All you have to do is execute the command
zstd [filename]. Using the above command creates a new, compressed file with the .zst extension.
For example, to compress a “samplecompression.text” in the “/var/log” directory, we would execute the command:
cd /var/log sudo zstd samplecompression.text
the following is an example output:
The above output shows the compression factor, i.e 44.08% from 1141 bytes for 503 bytes.
Compressing Multiple Files
To use zstd to compress multiple files simultaneously, all you have to do is specify the files you want to compress, separated by a space between them.
For example, to compress “compress.txt,” “compress2.txt,” “compress3.txt,” and “compress4.txt”:
sudo zstd compress.txt compress2.txt compress3.txt compress4.txt
You can also use the wildcard “*” to compress all the files and folders within your current/specified directory. For example:
sudo zstd *.txt
Decompressing Files with zstd
When you need to decompress a file with zstd, use the
-d option or
For example, to decompress the file used throughout this guide, you would use any of the following commands:
sudo zstd -d samplecompression.text.zst sudo unzstd samplecompression.text.st
Ensure the source of the file from the archive does not exist, or zstd will prompt you to overwrite the existing file.
This tutorial has illustrated how to compress and decompress files using the zstd utility. Meanwhile, you can learn how to extract zip files in Linux.
Our latest tutorials delivered straight to your inbox