Config Server Firewall

Learn How to use Curl Command in Linux with Examples

Curl is a powerful utility that can use to both download and upload data to servers. The curl command in Linux Supports many kinds of protocols, including HTTP/HTTPS, FTP, SMTP, SMB and More.

This tutorial Mainly Focuses on HTTP and FTP Protocol. First we will see how to use curl command to retrieve data through the HTTP Protocol, Then we will use curl with FTP protocol to Download and Upload files.

Retrieve Web Pages with curl command

Let's just run a simple curl command. Following example will retrieve webpage and print html output to the Linux terminal.


The data of the will be displayed to the Linux terminal. The output includes HTML Tags, it is not the result you see on the web browser.

Save Data to a File. curl command in Linux displays data to the terminal by default. To save data to a file, we need to use either -o flag (Lowercase 0) or -O flag (Uppercase o).

In the following example, we use -o option (lowercase 0). With -o option we specify the output file name.

curl -o example.html

This time output will not be sent to the Linux terminal. curl will retrieve the and save it to the example.html file.

With The -O (Uppercase O) flag, we do not specify output file name. It will automatically create an output file with the same name as the remote file. But, The -O option require specific remote file name (For example, index.html or index.php).

curl -O

This time curl command will download the "index.html" file from the and save it as "index.html".

Also note that you can put command options before or after the URL, it Makes No difference.

It is also possible to save the data to a file using output redirection as shown below.

curl > example.html

Display HTTP Response Headers

The curl command in Linux can display HTTP response-headers sent by the Web Server. To show response-headers, use the -I option.

curl -I

This will dump the HTTP Headers as shown in following screenshot.

curl command in linux display HTTP response-headers

Set User Agent in Curl Command

Sometimes Web Server and Firewall blocks default curl user agent. One possible solution for this is to set different user agent with --user-agent Flag.

In the following example, curl will use Fedora-Firefox user agent to retrieve data from the website.

curl --user-agent 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0'

Examples, Download Files with curl command

Following example will download the '' file from the website and preserve the original file name:

curl -O

In the following example, curl command in Linx will Download '' file from and save it as '':

curl -o

Download images and save using output redirection:

curl > /home/user/image1.jpg

Ask HTTP Server to provide compressed versions of the Data.

curl --compressed

Connect to FTP Server with curl Command

Now let's see how to use Linux curl command with FTP protocol. For the examples I will use following FTP Credentials.

To specify username and password we use the -u option.

curl -u username:password

Download Files From FTP Server.

Following command will download 'file1.txt' From the FTP Server. We are going to use -O option (Uppercase o), So the original filename will be preserved.

curl -u ftpuser:ftp123 -O

In the following example, we will download the 'file1.txt' From the FTP Server and save it as 'file2.txt' using the -o flag (Lowercase o).

curl -u ftpuser:ftp123 -o 'file1.txt'

Upload Files to the FTP Server

To upload files, curl command in Linux use the -T option followed by the name of the file wants to upload.

curl -u ftpuser:ftp123 -T file1.txt

Upload with a different filename. Following command will take 'file1.txt' and upload to the FTP Server as 'file2.txt'.

curl -u ftpuser:ftp123 -T file1.txt

Upload Multiple Files. To upload multiple files, put file names inside the curly brackets.

curl -u curlftp:ftp123 -T '{file1.txt,file2.txt}'

Linux Curl Command Tips and Tricks

Display Command Help:

curl --help

Run curl command in Verbose Mode. Run the command with the -v / --verbose option to get more information:

curl -v

Silent Mode. This opposite to verbose mode, Command will not show any error message or download progress.

curl -s -o output

Silent Mode with error messages enabled:

curl -s --show-error

Display Progress bar With # tags:

curl -# -o output_file

Max File Size. the --max-filesize flag use to specify the maximum size (in bytes) of a file to download. If file is larger than the max size, curl command in Linux will not download the file.

curl --max-filesize 1000 -O

Maximum Data Transfer Rate. The --limit-rate options set the maximum download or upload rate. By default speed is measured in bytes/second unless a suffix is appended (k for kilobytes, m for megabytes, g for gigabytes).

Following example will use maximum speed of 64 kilobytes per second.

curl --limit-rate 64k

Byte Range. --range flag use specify the byte range we want to transfer. For example, following curl command will download first 100 bytes from the index.html file.

curl --range 0-99