Zstd refers to the Zstandard which was developed by Yann Collect at facebook for a fast and real-time data compression. It was written in C but you could also find the APIs implementation of different popular languages such as Java, Python, JavaScript and many more. It is a lossless compression algorithm that has a better compression ratio as well as in-memory compression and decompression functions.
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.
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.
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.
To compress the files using zstd you need to execute the command with -z option which refers to compression.
$ zstd -z zstd/README.md
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
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
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
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
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
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.
2024 was the GenAI year. With new and more performant LLMs and a higher number…
Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…
Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…
At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…
I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…
Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…