---
title: "CURL Linux Command : Learning By Example"
description: "Learn through step-by-step examples with the indispensable CURL Linux tool and level-up your troubleshooting and scripting!"
canonical: "https://adamtheautomator.com/curl-linux/"
---

# CURL Linux Command : Learning By Example

> Learn through step-by-step examples with the indispensable CURL Linux tool and level-up your troubleshooting and scripting!

Source: https://adamtheautomator.com/curl-linux/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![CURL Linux Command : Learning By Example](https://adamtheautomator.com/wp-content/uploads/2022/09/CURL-Linux-Command-Learning-By-Example.jpg)

# CURL Linux Command : Learning By Example

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)28 September 20225 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Curl](/tag/curl/)[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing cURL Linux (Ubuntu)](#installing-curl-linux-ubuntu)
*   [Authenticating Websites](#authenticating-websites)
*   [Downloading Files With Original or Changed Name](#downloading-files-with-original-or-changed-name)
*   [Setting Connection Timeout](#setting-connection-timeout)
*   [Retrieving Data Using the GET Request](#retrieving-data-using-the-get-request)
*   [Sending a POST Request](#sending-a-post-request)
*   [Searching Word Definitions](#searching-word-definitions)
*   [Testing Website HTTP2 Protocol](#testing-website-http2-protocol)
*   [Conclusion](#conclusion)

Being an IT engineer comes with various tasks to perform, such as checking network connectivity, downloading files, or setting authentications. Usually, these tasks require different tools. Well, not with cURL. The cURL Linux utility helps with most things an IT engineer needs.

In this tutorial, you’ll learn about every command-line feature cURL provides.

Read on and level up your skills with cURL!

## Prerequisites

This tutorial comprises step-by-step demonstrations. To follow along, ensure you have the following:

*   An Ubuntu machine – This tutorial uses [Ubuntu 18.04](https://releases.ubuntu.com/18.04/) with [Apache installed](https://httpd.apache.org/download.cgi).

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

Related:[How to Install Apache on Ubuntu to Manage your Traffic](https://adamtheautomator.com/install-apache-on-ubuntu/)

*   A Windows XP+ PC – This tutorial uses Windows 10 Enterprise edition.
    
*   A remote Linux host – This tutorial uses an [Ubuntu 18.04.5 LTS](https://releases.ubuntu.com/18.04/) machine.
    
*   A user account on the remote Linux SSH host with sudo permissions.
    

## Installing cURL Linux (Ubuntu)

Like any other tool, before taking advantage of cURL, you first have to install it on your machine. You can install cURL on any \*nix-based operating system, but it is most popularly used on Ubuntu.

cURL is a command-line utility that allows you to perform tons of tasks as follows:

*   Display the status of various network configurations of Windows machines or Linux servers
*   Transfer data to or from servers
*   Supports multiple protocols, such as HTTP, FTP, IMAP, POP3, SCP, and SFTP.

To install cURL on your Ubuntu machine:

1\. Connect to your Ubuntu host with your favorite SSH client.

2\. Run the following commands, which don’t provide output but create a directory named _~/install\_curl\_demo_ and switch to that directory. This directory will hold all resources you’ll create in this tutorial.

```bash
mkdir ~/install_curl_demo
cd ~/install_curl_demo
```

3\. Next, run the below [apt update](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update) command to update your system package index.

This command ensures the apt package manager can find the proper source when downloading any dependent packages.

```bash
sudo apt update 
```

![](https://adamtheautomator.com/wp-content/uploads/2022/09/image-427.png)

Updating the Ubuntu machine with the latest packages

Related:[Learning Ubuntu Apt Get Through Examples](https://adamtheautomator.com/ubuntu-apt-get/)

4\. Now, run the [apt install](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) command below to install cURL on your machine.

```bash
sudo apt install curl
```

![Installing cURL on the Ubuntu machine](https://adamtheautomator.com/wp-content/uploads/2022/09/image-428.png)

Installing cURL on the Ubuntu machine

5\. Finally, run the below command to check the cURL’s version installed on your machine. Doing so ensures that you’ve successfully installed cURL.

```bash
curl --version
```

![Checking cURL’s version installed](https://adamtheautomator.com/wp-content/uploads/2022/09/image-429.png)

Checking cURL’s version installed

## Authenticating Websites

Different protocols curl support, such as FILE, FTP, HTTP, HTTPS, POP3, SCP, SFTP, TELNET, etc., and you don’t need to work with any user interaction.

If you need to authenticate to any website using the curl command, you will need to specify the user and password in the URL itself. But if you set the user name, cURL will prompt a password.

Run the below curl command, replacing automateinfra@gmail.com:password with your username and password and the website URL with yours to authenticate.

```bash

curl -u automateinfra@gmail.com:password --basic <https://wordpress.com/posts/automateinfra.com> 
```

![Authenticating user with password](https://adamtheautomator.com/wp-content/uploads/2022/09/image-430.png)

Authenticating user with password

## Downloading Files With Original or Changed Name

Downloading files or packages may be part of your daily routine as an admin. If so, cURL will surely do you a favor. The `curl` command, appended with either the `-O` or `-o` options, lets you download files while keeping the original or setting a different name.

Run the below commands to download the NGINX package with the original name (`-O`) as (`*nginx-1.20.2.tar.gz*`) and with a different name (`-o`) as `*mytar.gz*`.

```bash
# Downloads the NGINX package with the original name nginx-1.20.2.tar.gz
curl -O <http://nginx.org/download/nginx-1.20.2.tar.gz>
# Downloads the NGINX package with the new name mytar.gz
curl -o mytar.gz <http://nginx.org/download/nginx-1.20.2.tar.gz>
```

![Downloading the NGINX package](https://adamtheautomator.com/wp-content/uploads/2022/09/image-431.png)

Downloading the NGINX package

Now, run the following command to download the NGINX package named mytar2.gz. But this time, you’ll only see a progress bar instead of seeing lots of details in the output.

```bash
curl -# -o mytar.gz <http://nginx.org/download/nginx-1.20.2.tar.gz>
```

![Downloading the NGINX package but only showing a progress bar](https://adamtheautomator.com/wp-content/uploads/2022/09/image-432.png)

Downloading the NGINX package but only showing a progress bar

Lastly, run the `ls` command below to list all files in the current directory.

```bash
ls
```

Below, you can verify that _**nginx-1.20.2.tar.gz**_, _**mytar.gz**, and **mytar2.gz**_ files exist.

![Verifying downloaded NGINX packages](https://adamtheautomator.com/wp-content/uploads/2022/09/image-433.png)

Verifying downloaded NGINX packages

## Setting Connection Timeout

Fast-loading websites are always ideal, and cURL has a way to test how fast a user can connect to your website. How? By setting a connection timeout, where the `curl` command tries to connect to a website within a specific timeframe.

Setting a connection timeout lets you determine how long a server is taking to reply to a data request you make.

Run the below command to try and connect to the [adamtheautomator.com](http://adamtheautomator.com) site for `20` seconds before timing out the request.

```bash
curl --connect-timeout 20 -I adamtheautomator.com
```

You can see below that the `-I` option lets you include headers in the website’s information output.

![Connecting to a website with a connection timeout](https://adamtheautomator.com/wp-content/uploads/2022/09/image-434.png)

Connecting to a website with a connection timeout

## Retrieving Data Using the GET Request

You’ve seen setting connection timeout provides information about a website in the “Setting Connection Timeout” section. But if that information is not enough, consider sending a GET request.

Run the curl command below to use an HTTP GET request (–get) and retrieve data from the [https://adamtheautomator.com](https://adamtheautomator.com/) website.

```bash
curl --get <https://adamtheautomator.com>
```

Below, you can see the actual source of the [adamtheautomator.com](http://adamtheautomator.com) website.

![Retrieving data using the Get request](https://adamtheautomator.com/wp-content/uploads/2022/09/image-435.png)

Retrieving data using the Get request

## Sending a POST Request

Instead of getting data, you can also send data by sending a POST request with the `curl` command. The `-d` parameter allows you to send the specified data in a POST request to the HTTP server like a browser does when a user has filled in an HTML form.

Run the following `curl` command to send a POST request to the `ptsv2.com` site.

```powershell
curl -d "name=curl" <https://ptsv2.com/t/hello>
```

![Sending the POST request on a website](https://adamtheautomator.com/wp-content/uploads/2022/09/image-436.png)

Sending the POST request on a website

Now, navigate to [https://reqbin.com/](https://reqbin.com/) on your web browser to test if the POST was successful.

Below, you’ll notice the Status shows (200 (OK), which signifies the request was sent successfully.

![Verifying the POST request](https://adamtheautomator.com/wp-content/uploads/2022/09/image-437.png)

Verifying the POST request

## Searching Word Definitions

Did you know you can also use cURL like a dictionary? Yes! cURL lets you search word definitions by using the [DICT protocol](https://everything.curl.dev/protocols/curl#dict). Many IT-related terms can be searched using the DICT protocol, such as clock, ubuntu, RDP, etc.

The syntax of the `curl` command using the DICT protocol is as follows:

```bash
curl [protocol:[dictionary_URL]:[word]
```

Run each command below to search for word definitions from the dictionary available on the public website `dict.org`.

```bash
# Search word definitions for ubuntu
curl dict://dict.org/d:ubuntu
# Search word definitions for clock
curl dict://dict.org/d:clock
```

As you can see below, the first word definition search for **ubuntu** couldn’t find a relevant answer and returned **no match**. But the second one returned a couple of definitions for the word **clock**.

![Searching the word definition](https://adamtheautomator.com/wp-content/uploads/2022/09/image-438.png)

Searching the word definition

## Testing Website HTTP2 Protocol

The curl command is undoubtedly suitable for downloading, uploading, and authenticating websites. But another thing making curl a great tool is that you can check whether a particular URL supports the new [HTTP/2 protocol](https://en.wikipedia.org/wiki/HTTP/2).

Run the following curl command to verify if the _https://adamtheautomator.com/_ website supports HTTPS protocol (–http2).

```powershell
curl -I --http2 -s <https://adamtheautomator.com/> | grep HTTP
```

You’ll see an HTTP/2 200 response in the output like the one below, which signifies the site uses the HTTP2 protocol.

![Testing Website HTTP2 protocol using Curl Command](https://adamtheautomator.com/wp-content/uploads/2022/09/image-439.png)

Testing Website HTTP2 protocol using Curl Command

## Conclusion

cURL, while a free tool, comes with many features. And in this tutorial, you’ve experienced different first-hand examples of using cURL in Linux. Whether downloading files, authenticating websites, sending POST or GET requests, etc., cURL won’t disappoint you.

Why not build on this newfound knowledge? Perhaps learn how to transfer files, and run commands and scripts using the curl command? Or discover cURL API commands?

Related:[Essential CURL API Commands for Testing & Troubleshooting](https://adamtheautomator.com/curl-api/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fcurl-linux%2F&text=CURL%20Linux%20Command%20%3A%20Learning%20By%20Example)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fcurl-linux%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fcurl-linux%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/08/Discover-the-Many-Ways-to-Get-an-IP-Address-on-Linux.jpg)

### [Get an IP Address on Linux : Discover the Many Ways](/get-an-ip-address-on-linux/)

Discover the many ways and tools that are available to get an IP address in Linux and learn how to incorporate those tools into scripts!

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
