In this article, you will learn about different usages of zstd compression as well as how to install it. All the demonstrations in the article are performed in the Ubuntu 20.04 LTS system.
Installing Zstandard in Linux
There is no officially maintained package for zstd so you need to compile it from sources. To do so you need to build_essential package in order to compile c software from source.
$ sudo apt update
$ sudo apt install build-essential git -y
Now, clone or download the zstd source code from its official github repo. Then use the make command to compile the source and install it in the following way.
$ git clone https://github.com/facebook/zstd.git
$ cd zstd
$ sudo make
$ sudo make install
You have successfully installed the zstd on your system. Now, you can compress and decompress files, documents on your system. Next we will be discussing some of the uses of it.
Some of the Usages of Zstd with Example
Using zstd is way too similar to other compression and decompression methods. Even though it has a different way of implementation from other tools, it has a similar syntax of tar and gzip for compressing files. I will be using the source code of zstd which we downloaded earlier to install it.
Compressing Using Zstd
To compress the files using zstd you need to execute the command with -z option which refers to compression.
$ zstd -z zstd/README.md
Decompressing Using Zstd
To decompress you need to use the -d option to the command and specify the path to the file.
$ zstd -z zstd/README.md.zst
View Information on Compress File
You can view more information of the zstd compressed file using the -l option which shows information on the compression ratio, file checksum and file size.
$ zstd -l zstd/README.md.zst
Remove Source File After Compression
When you compress the file the source file doesn’t remove by itself after the compression is complete. If you wish to remove the compression source file after the compression is completed you need to execute the command with the –rm option in order to do so.
$ zstd -z --rm zstd/README.md
Increase/Decrease Compression Speed
By default, the compression speed of zstd is 1 but you can set the value of ranging from 1-10. During compression you can specify the speed using –fast option, the higher the value the faster the zstd compresses the file.
$ zstd -z --rm --fast=4 zstd/README.md
Displaying Verbose On Compression
The verbose shows more detailed information on the actual process during compression or decompression. To display the verbose you need to provide the -v option to the command.
$ zstd -zv zstd/README.md
Specifying the Compression Level
You can specify the compression level of zstd. The compression level ranges from 1-19 and has a default compression level of 3. You can specify the level using – with the level of compression to the command.
$ zstd -zv -8 zstd/README.md
Thank you for reading this article. I assume this article helps you set the concept on what is zstd and how we can install and use it in the Linux system.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.