Download File Using Curl Mac

Tar (Tape Archive) is a popular file archiving format in Linux. It can be used together with gzip (tar.gz) or bzip2 (tar.bz2) for compression. It is the most widely used command line utility to create compressed archive files (packages, source code, databases and so much more) that can be transferred easily from machine to another or over a network.

Read Also: 18 Tar Command Examples in Linux

In this Linux/Mac terminal tutorial, we will be learning how to use the cURL command. The curl command allows us to query URLs from the command line.

In this article, we will show you how to download tar archives using two well known command line downloaders – wget or cURL and extract them with one single command.

How to Download and Extract File Using Wget Command

The example below shows how to download, unpack the latest GeoLite2 Country databases (use by the GeoIP Nginx module) in the current directory.

Download File Using Curl Mac

The wget option -O specifies a file to which the documents is written, and here we use -, meaning it will written to standard output and piped to tar and the tar flag -x enables extraction of archive files and -z decompresses, compressed archive files created by gzip.

Curl Download File Example

To extract tar files to specific directory, /etc/nginx/ in this case, include use the -C flag as follows.

Note: If extracting files to particular directory that requires root permissions, use the sudo command to run tar.

Alternatively, you can use the following command, here, the archive file will be downloaded on your system before you can extract it.

To extract compressed archive file to a specific directory, use the following command.

How to Download and Extract File Using cURL Command

Considering the previous example, this is how you can use cURL to download and unpack archives in the current working directory.

To extract file to different directory while downloading, use the following command.

That’s all! In this short but useful guide, we showed you how to download and extract archive files in one single command. If you have any queries, use the comment section below to reach us.

Curl command file utility supports for downloading and uploading files. Curl is useful for many works with system administration, web development for calling web services, etc. In this tutorial we are providing 5 curl frequently used commands to download files from remote servers.

1. cURL Command to Download and Save File

To simply download a file using curl use following syntax. -O is used for saving file on the local system with the same name on the remote system.

2. cURL Download and Save with Other Name

If you want to save file with different name on local system, Use -o with new file name.

3. cURL to Download Multiple Files

Curl also provides an option to download multiple files simultaneously. To download multiple file use following syntax. All files will be saves with original file names.

4. Passing Login Credential with cURL Download

In case files are behind authenticated http or ftp server. You can pass login credentials using -u command line parameter like below examples.

Use Curl To Download File

5. cURL Download File via Proxy Server

Download File Using Curl Macrame

If server file is only available through a proxy server, or you want to use a proxy for downloading files, Use -x followed by proxy address and port to download the file via a proxy server.