How to Extract .GZ and .TAR.GZ Files in Linux | Hands on Cloud
When transferring files over the network, it’s more preferable to transfer a single file (usually .gz or .tar.gz archive). Such an approach allows minimizing disk IO operations and speed up the file transmission process. A single file of 1GiB in size will be transferred faster than 1024 files of 1MiB in size. In this article, we’ll look at the process of extracting and .gz and .tar.gz files in Linux.
There are two most commonly used utilities for extracting and opening a file archives in Linux:
gzip is the most commonly used tool in the Linux world that reduces file size using Lempel-Ziv coding (LZ77) while keeping the original file mode, timestamp, and ownership.
By the way, the same algorithm is used for compressing web elements which allows loading web pages faster.
Usually, gzip-compressed file ends with a .z or .gz file extension.
As an example, let’s download an archive of WordPress, the most popular CMS:
1. How to Open and Extract .gz files in Linux — Download WordPress
Now, you can extract it:
gzip -d latest.tar.gz
3. How to Open and Extract .gz files in Linux — gzip
You’ll achieve the same result if you use gunzip command which is an alias for gzip -d command:
2. How to Open and Extract .gz files in Linux — gunzip
The result in both cases will be the same, the tar archive.
But, wait, why do we need two archives?!
The difference between ‘gzip’ and ‘tar’
gzip is an archival utility that is responsible for the compression of the file, but it does not support multiple files. Initially, it was designed to compress only one file at a time.
tar is an archival utility meaning that it is responsible for putting multiple file to a single file which is called “archive” too.
At the beginning of the Unix world, tar archives were used to store files on magnetic tapes. The name “tar” comes from this use; it stands for tape archiver.
That’s why we need tar.
The tar utility initially was responsible for putting multiple files into a single location (a magnetic type, which was the only backup storage available). Nowadays, when the storage is cheap and available, tar is used to put the files into a single file.