Essential File Compression Tools in Linux - Tar, Zip and Gzip

File compression is an important practice for all operating systems, including Windows, Linux, and Mac OS. Compressing files reduces the file size to a smaller fraction, consuming fewer resources and rendering file sharing speedy, simple, and cheap without missing any vital component of such file. On Linux, file compression aids in storage optimization.

In a nutshell, file compression facilitates the transfer of files from one endpoint to another while maintaining a small file size.

Methods of compression and uncompression files in Linux.

  1. Tar

Tape archive popularly known as tar is one of the command line tools used to compress and uncompress files and folders in Linux. Tar takes a bunch of files and puts them together in one container, reducing the size to a certain percentage and is subject to further compression using another tool called gunzip. The tar expressions and toolset are known as Tarballs.

To compress a file using the tar tool

$ tar czvf <filename.tar> <path to file>

Where $ tar is the command, czvf is to create a new archive, z to create an archive through gunzip, verbose the output, and specify the file name. filename.tar is the name of the file with the .tar extension to signify the compression type, and the name of the file or path to the file is the location of the file. If you are in the directory where the files are and you want to compress all the items. Simply use period(.) instead of the path to file.

To uncompress a tar file

$ tar -xzvf <filename.tar>

Where x is used to extract from a compressed file.

  1. Zip

Zipped files use fewer storage resources and transmit faster to other computers than uncompressed files. Even though zipping is a compound term that refers to compressing huge files and folders using any archive file format. Zip is a tool that operates similarly to other compression tools in that the contents of the folder are reduced to improve storage performance.

To compress and uncompress a file using a zip tool

$ zip <new file/foldername> <file/foldername>

$ unzip <file name>

When a file or folder is unzipped in the same local machine where it was zipped, it returns to the original name it had before it was zipped.

  1. gzip

Gunzip(gzip) further compresses a tar file by reducing to the barest minimum the size of a compressed tar file.

To compress a tar file using gzip

$ gzip <filename.tar>

To uncompress a gzip file

$ gzip -d <filename.tar.gz>