Debian

10 Best File Compression Tools in Debian

Data compression is a vast field that is continually being researched. We have hundreds of algorithms in place to compress our data, and these algorithms are offered to us as an abstraction in the form of various applications and tools. Let us look at the best data compression technologies and tools available in Debian.

What is Compression?

Data compression is the process of reducing the size of the data by reducing the number of binary digits that represent the data. Data compression can help you conserve storage space, speed up file transfers, and save money on storage hardware and network bandwidth. The software performs data compression using an algorithm to decide how to reduce the amount of data. For instance, an algorithm may represent a sequence of bits containing 1s and 0s with a smaller number of 0s and 1s by mapping them using a dictionary.

Lossless vs. Lossy Compression

Lossless compression is the process of reducing the size of a file by compressing data into a smaller space by evaluating it and putting frequently encountered data in a smaller place. The “Huffman Coding” algorithm is a common lossless compression algorithm.

Lossy compression and, on the other hand, purposely loses data to compress pictures. This approach may appear to be a disadvantage for us, but it is quite useful when delivering enormous photos and videos across the network.

How to Get Install Packages in Your Debian Distribution

apt-get is the package manager used in Debian distribution to install a package. Use the following syntax to install a compression tool on your machine.

$ apt-get install <package_name>

Many compression tools may not be available in the form of a package, and you will need to download them as software.

tar
In Linux, the tar is a utility (tar = tape archive, derived from when data was stored in magnetic tapes) used to ‘archive’ or compile one or more files and directories into a single file.

To create an archive file, use the below command:

$ tar -cvfz <file.tar.gz> <file>

-z options will compress the file in the above command.

Gzip
Gzip is a widely used compression utility in Debian. It was created and is maintained as part of the GNU project. It allows for lossless compression. This utility may be used in both CLI and GUI modes.

It compresses files using the LZ77 and Lempel–Ziv–Welch algorithms. You may also use this tool to compress many files at the same time. To compress the file, use the following syntax.

$ gzip <file>

The command file creates a new file with the additional extension as “.gz”.

To decompress the file, use the command below:

$ gzip -d <compressed_file>

BZip2
It is an open-source file compression tool written in C. Julian Seward was the creator of this tool. It employs the “Prediction by Partial Matching” approach to shorten the data compression time. It may also be used to compress raw data because it employs “Huffman Coding” for lossless compression.

This tool allows data to be sent and compressed at the same time. Use the below command to compress the file.

$ bzip2 <file>

To decompress the file, use the command:

$ bzip2 -d <compressed_file>

Lzma
It is a file compression tool that provides better compression ratios than Gzip, BZip2. This is a shorthand for Lempel-Ziv-Markov chain Algorithm. It is derived from the LZ77 compression algorithm. This algorithm is pretty fast and efficient but consumes high amounts of RAM. However, you can limit the RAM usage in it. The default limit of RAM usage is 40% of the total memory.

To compress using this tool, use the following command:

$ lzma <file>

To extract the compressed file:

$ unlzma <file.lzma>

PAX
It is another efficient tool that is used to create archived files. This is a shorthand for “Portable Archive Interchange”. The important advantage of this tool is that it is not restricted to a single archive format but supports multiple formats. It was developed to unify the formats of archived files. This tool supports four modes of operation namely read, write, list and copy.

To extract the data of a file into the present working directory:

$ pax -r < <file.tar>

Create an archive of the current directory:

$ printf '.' | pax -w > <file.tar>
$ pax -w . > <file.tar>

7zip compressor
It is an open-source utility that was initially developed for Windows but can now be used in Debian. It supports compressing multiple files at once, and this also allows you to extract disk image files. It uses Advanced Encryption Standard (AES) for file-encrypting purposes.

To compress a file:

$ 7z  a <file.7z> <file>

To extract a file, use the following command

$ 7z  e <file.7z>

Shar
It is derived from the “Shell Archive” and is used for creating archives of shell scripts. Archives are individual files that contain multiple directories and files as a single compressed file. These archived files can be unpacked by executing them as shell scripts. The extension of the archive files created with this tool is “.shar” which is a popular UNIX-like system archive files extension. However, these archived files have one disadvantage of being executed through scripts, which makes it vulnerable.

To create an archive file, use the following command

$ shar <file> > <file.shar>

To decompress the file, use:

$ unshar <file.shar>

Disk Imaging

A disc image is a snapshot of the data on our disc. “ISO” is a commonly used suffix for an image of a disc formatted using a filesystem that corresponds to the ISO 9660 file system standard, also known as CDFS, and is designed for usage on compact discs. A disc image is simply an electronic representation of the data as it would appear on a disc (in this case, a CD-ROM or DVD).

The disc image might contain everything that would normally be stored on a drive, such as an operating system, data, software, media files, and so on.

LZ4
LZ4 is a compression tool written in C that is used in Debian. It is capable of compressing up to 0.5 GB of data per second. This utility employs the lossless compression algorithms LZ4 HC and LZ77.

To compress a file, use the following command:

$ lz4 [OPTIONS] [-|FILE] OUTPUT-FILE

To decompress a file, use either of the following commands:

$ lz4 -d <compressed_file>

OR

$ unlz4 <compressed_file>

Zstandard
This compressing tool was developed by Facebook and was created in C#, Java, Python, Rust, and PHP. You may also use it on your websites to compress files.

It can compress data at a rate of up to 500MB per second. The decompression rate may reach 1660MB per second.

It may even compress and decompress data at the same time. To minimize compression time, Zstandard employs the “dictionary compression” approach.

To compress a file, use the below command:

$ zstd -z <file>

This creates a compressed file with the extension “.zst”.

To decompress a file, use:

$ unzstd <compressed_file>

Conclusion

This article covered the top compression tools for Linux and Debian users. These tools abstract lossy and lossless compression methods and allow us to compress data with only one line of code. These compression tools are reliable, secure, quick, and are extensively utilized in the development community.

About the author

Simran Kaur

Simran works as a technical writer. The graduate in MS Computer Science from the well known CS hub, aka Silicon Valley, is also an editor of the website. She enjoys writing about any tech topic, including programming, algorithms, cloud, data science, and AI. Travelling, sketching, and gardening are the hobbies that interest her.