{"id":10906,"date":"2021-10-05T08:46:44","date_gmt":"2021-10-05T08:46:44","guid":{"rendered":"https:\/\/linuxways.net\/?p=10906"},"modified":"2021-10-05T08:46:44","modified_gmt":"2021-10-05T08:46:44","slug":"zstd-open-source-data-compression-algorithm-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/zstd-open-source-data-compression-algorithm-in-linux\/","title":{"rendered":"zstd &#8211; Open-Source Data Compression Algorithm in Linux"},"content":{"rendered":"<p>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.<\/p>\n<p>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.<\/p>\n<h2>Installing Zstandard in Linux<\/h2>\n<p>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.<\/p>\n<pre>$ sudo apt update<\/pre>\n<pre>$ sudo apt install build-essential git -y<\/pre>\n<p>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.<\/p>\n<pre>$ git clone https:\/\/github.com\/facebook\/zstd.git<\/pre>\n<pre>$ cd zstd<\/pre>\n<pre>$ sudo make<\/pre>\n<pre>$ sudo make install<\/pre>\n<p>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.<\/p>\n<h2>Some of the Usages of Zstd with Example<\/h2>\n<p>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.<\/p>\n<h3>Compressing Using Zstd<\/h3>\n<p>To compress the files using zstd you need to execute the command with -z option which refers to compression.<\/p>\n<pre>$ zstd -z zstd\/README.md<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"116\" class=\"wp-image-10907\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image.jpeg\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image.jpeg 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-300x48.jpeg 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<h3>Decompressing Using Zstd<\/h3>\n<p>To decompress you need to use the -d option to the command and specify the path to the file.<\/p>\n<pre>$ zstd -z zstd\/README.md.zst<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"139\" class=\"wp-image-10908\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-1.jpeg\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-1.jpeg 726w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-1-300x57.jpeg 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/p>\n<h3>View Information on Compress File<\/h3>\n<p>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.<\/p>\n<pre>$ zstd -l zstd\/README.md.zst<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"138\" class=\"wp-image-10909\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-2.jpeg\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-2.jpeg 730w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-2-300x57.jpeg 300w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/p>\n<h3>Remove Source File After Compression<\/h3>\n<p>When you compress the file the source file doesn\u2019t 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 &#8211;rm option in order to do so.<\/p>\n<pre>$ zstd -z --rm zstd\/README.md<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"171\" class=\"wp-image-10910\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-3.jpeg\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-3.jpeg 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-3-300x70.jpeg 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<h3>Increase\/Decrease Compression Speed<\/h3>\n<p>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 &#8211;fast option, the higher the value the faster the zstd compresses the file.<\/p>\n<pre>$ zstd -z --rm --fast=4 zstd\/README.md<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"140\" class=\"wp-image-10911\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-4.jpeg\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-4.jpeg 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-4-300x58.jpeg 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<h3>Displaying Verbose On Compression<\/h3>\n<p>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.<\/p>\n<pre>$ zstd -zv zstd\/README.md<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"155\" class=\"wp-image-10912\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-5.jpeg\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-5.jpeg 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-5-300x64.jpeg 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<h3>Specifying the Compression Level<\/h3>\n<p>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 &#8211; with the level of compression to the command.<\/p>\n<pre>$ zstd -zv -8 zstd\/README.md<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"116\" class=\"wp-image-10913\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-6.jpeg\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-6.jpeg 729w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-6-300x48.jpeg 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>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.<\/p>","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>","protected":false},"author":1,"featured_media":10948,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[604,35],"class_list":["post-10906","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-data-compression-algorithm","tag-linux"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/10906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=10906"}],"version-history":[{"count":1,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/10906\/revisions"}],"predecessor-version":[{"id":10947,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/10906\/revisions\/10947"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/10948"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=10906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=10906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=10906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}