Table of contents
When transferring files over the network, it’s more preferable to transfer a single file (usually
.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
.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.
gzip-compressed file ends with a
.gz file extension.
As an example, let’s download an archive of WordPress, the most popular CMS:
Now, you can extract it:
gzip -d latest.tar.gz
You’ll achieve the same result if you use
gunzip command which is an alias for
gzip -d command:
The result in both cases will be the same, the
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 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.
Let’s get WordPress files:
tar xf latest.tar
Here we’re using the following arguments:
- x – tells
tarto extract its archive
- f – tells tar the location of the file archive
As a result of this operation, we got a
The process of extracting files in multiple steps is not convenient, so that’s why
tar supports additional argument process its archive through gzip. The same operation, but only one command:
tar zxf latest.tar.gz
Here, we’re using an additional argument:
- z – tells
tarto filter its archive through
We unzipped files and extracted them from the
tar archive using only one single command.
In the Linux operating system, the .gz file archives are commonly used in combination with tar archives that allow compressing multiple files at once. This article provided a complete guide on extracting and opening
.tar.gz files in Ubuntu.