Commands To Download & Extract TAR Files in Linux

In this tutorial, we give you all the necessary steps to know what are the commands to download and extract TAR file in Linux

What is TAR?

The tar command (Tape Archiver) is an official POSIX format through which it will be possible to execute tasks such as:

  • Use with other commands for file compression
  • Download multimedia elements
  • Transfer files and much more.

How To Download & Extract Files using WGET

Wget or GNU Wget is a free software package that allows us to manage files using HTTP, HTTPS, FTP and FTPS protocols.

With Wget, we have a series of advantages like

  • Recover failed downloads
  • Manage files of different languages thanks to the fact that it is based on NLS
  • Supports HTTP cookies and proxies
  • It allows being executed in unattended mode.

In this first example, we will see how to download and unzip a rar file.

For this we will execute the following line:

wget -c -O - | tar -xz

In this case, we will download the Geolite database utility.

If we wish we can list the content of the downloaded file:


We will break down that it has been executed in this line:


The parameter O indicates the file where the data are to be written, and when the – sign is prefixed, we suggest that you store it in standard output.


This parameter allows us to activate the extraction of files


Its function is to compress or unzip the selected file.

If we want to extract the content of the downloaded file in a different route, it will be necessary to add the parameter -C in the following way:

sudo wget -c -O - | sudo tar -xz -C path

Wget is a tool that allows us to execute various actions; for example, if we want to download the file before its extraction we will run the following:

sudo wget -c && tar -xzf GeoLite2-Country.tar.gz

We can see that in this case the file has been downloaded in tar.gz format but not uncompressed.

How To Download & Extract Files using CURL

This command has been developed as a command line utility or scripts to transfer data securely.
Curl supports protocols such as HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP and many more.

To download a file with the curl command and proceed to its immediate decompression, we will execute the following:

sudo curl | tar -xz

We have used ls to list that the file has been decompressed.

As with wget, it is possible to specify a new path where the file must be extracted, for this we can use some of the following commands:

sudo curl | sudo tar -xz -C path
sudo curl && sudo tar -xzf GeoLite2-Country.tar.gz -C path

So we have understood how to use tar along with other commands for downloading and decompressing files in Linux.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *