×


Zstandard - An Open-Source Data Compression Algorithm for Ubuntu Linux system

Zstandard also referred to as Zstd 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.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related data compression queries on Linux systems.

In this context, we shall look into different usages of zstd compression as well as how to install it on Ubuntu 20.04 LTS system.


How to Install Zstandard on Ubuntu Linux 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. Now execute the below commands:

$ 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 by running the below commands:

$ git clone https://github.com/facebook/zstd.git
$ cd zstd
$ sudo make
$ sudo make install

Now that zstd has been successfully installed on your system, you can compress and decompress files, documents on your system. 


Some use cases of Zstd ?

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. 

To compress Using Zstd:

Here, you need to execute the command with -z option which refers to compression:

$ zstd -z zstd/README.md

To decompress Using Zstd:

Simply use the -d option to the command and specify the path to the file as shown below:

$ zstd -z zstd/README.md.zst


How to 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


How to 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


How to 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. The command is shown below:

$ zstd -z --rm --fast=4 zstd/README.md


How to Display 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


How to Specify 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


[Need assistance in fixing Linux system application errors? We can help you. ]


Conclusion

This article covers how you can install zstd and how to use it on your Ubuntu Linux system. In fact, Zstandard is a fast compression algorithm, providing high compression ratios. It also offers a special mode for small data, called dictionary compression.