Linux Commands

Top 10 File Compression Utilities on Linux

Transferring files between one computer to another or storing them securely is a major task to both normal and professional users. Sometimes it is not possible to send files above a certain size over the internet, so you need utilities that will help decrease your file size without compromising data or its quality. It also helps merge multiple files and reduce the overall file size to help you send it securely over the internet.

Linux users are blessed with many effective and reliable file compression utilities at their disposal.

The majority of utilities listed here work well with all the Linux distros, and we have tested them on Ubuntu.

tar

The tar file compression is one of the most widely used file compression utilities on Linux. File compressed with this utility have suffix .tar.gz and .tgz, and they are also called tarballs.

For example, if we have a file/directory named swap1 in the current directory. To save it to a compressed file named file.tar,gz, we have to run the following command in terminal:

$ tar -czvf file.tar.gz swap1

You might be wondering what does exactly switch -czvf means, let’s see it one-by-one.

-c : Create an Archive
-z : Compress Archive with gzip
-v : known as “verbose”. It displays the progress in the terminal window when the archive is being created.
-f : This switch allows you to specify the file name of the archive.

Install it by running the following command in the terminal:

$ sudo apt-get install tar

gzip

The gzip stands for GNU Zip, and it is an open-source file compression format used to compress single files. It produces zipped files with the suffix .gz extension.

ZIP and GZIP, are both very popular file compression formats when it comes to saving space and reducing the time required to send the file over the internet.

Here is its basic syntax:

$ gzip [Options] [filenames]

Using switch -l will give you detailed information about the compressed file.

To unzip a file use syntax:

$ gzip -d filename.gz

To install gzip, run the following command in the terminal:

$ sudo apt-get install gzip

7zip

The 7zip is an open-source file compression utility that was initially developed for Windows users and was later ported to other operating systems like Linux and its distros. It supports multiple file compression formats and is popular for a high compression ratio with LZMA and LZMA2 compression techniques.

Syntax:

$ 7z a filename.7z filename

To extract:

$ 7z e filename.7z

To install 7zip, run the following command in the terminal:

$ sudo apt-get install p7zip-full p7zip-rar

lzma

The lzma is another file compression utility like zip or tar, and it ships-in pre-installed with Linux and its distros. It is quite a fast file compression utility as compared to others.

To create archive:

$ lzma -c --stdout filename> filename.lzma

To extract files:

$ lzma -d --stdout filename.lzma >filename

bzip2

The bzip2 is a free and open-source file compression utility. It is a faster file utility as compared to gzip but can only compress a single file at a time.
Syntax:

$ bzip2 filename

This technique uses more RAM during compression. To reduce its use, switch –s, as shown below:

$ bzip2 -s filename

To extract:

$ bzip2 -d filename.bz2

xz file compression

The xz is an upgrade to the lzma file compression utility but can only compress a single file at a time. It integrates well with all the Linux distros, even the older releases.

Syntax to compress:

$ xz filename

Syntax to extract:

$ xz -d filename.xz

shar

The shar, short for “shell archive”, is a simple and reliable file compression utility for personal and power users.

Syntax to compress:

$ shar filename > filename.shar

Syntax to extract:

$ unshar filename.shar

To install shar, run the following command in the terminal:

$ sudo apt-get install sharutils

ar

The ar is a widely used file compression utility in Debian and its derivatives.

Syntax to compress:

$ ar cvsr filename.a filename

Syntax to extract:

$ ar -xv filename

kgb

The kgb is free to use file compression utility with support for the majority of file formats. It supports archiving multiple files into one with a high compression ratio.

Syntax to archive:

$ kgp filename.kgb filename

Syntax to decompress:

$ kgb x filename.kgb

To install kgb, run the following command in the terminal:

$ sudo apt-get install kgb

pax

The pax stands for Portable Archive Exchange, and it is a file compression utility used in creating and extracting archives. It supports various file compression formats like tar, cpio, bcpio, and ustar.

Syntax to compress:

$ pax -wf filename.tar filename

Syntax to decompress:

$ pax -r  < filename.tar

To install pax, run the following command in the terminal:

$ sudo apt-get install pax

So, these are the top 10 file compression utilities for Linux and its distros. There are still other compression utilities for Linux, but these 10 are the standouts when tested on various parameters. Feel free to share your views with us at @linuxhint and @SwapTirthakar.

About the author

Swapnil Tirthakar

A Software Engineer who loves football and passionate about traveling. I often spend my free time playing with gadgets and exploring new possibilities in tech world. I am Linux enthusiast and have about 6 years of experience in web development. I have good command on Python, Java, SQL and system security.