Learn how to use the curl command: tutorial with practical examples

Today we are going to learn about the curl command in Linux! This command is an incredibly versatile and powerful tool that goes far beyond simply downloading web pages.

We will explore the functionalities of curl and discover a universe of possibilities for interacting with the internet and automating tasks.

In the next sections, we will learn some cool and useful things you can do with curl, from the basics to some more advanced and even fun features.

Viewing the HTML Code of a Web Page with curl

Here we will use curl to display the HTML source code of a web page directly in your terminal.

  • Displaying the HTML source code of a web page is useful for:
  • Understanding a website’s structure and checking the page skeleton behind the visual interface.
  • Debugging web issues and verifying whether the HTML is functioning correctly when developing or testing websites.

Let’s use the command below to test the curl command.

curl https://simplificandoredes.com

https://simplificandoredes.com: This is the URL (web address) you want to access. You can replace it with another URL.

Saving the Content of a Page to a File

We can use curl to download files directly. This way, we can download files accessible via URL, such as images, PDFs, ZIP files, videos, and much more.

Downloading files with curl can be useful for:

  • Automating downloads in routine scripts.
  • Downloading files quickly without a browser.
  • Downloading files via command line on servers that do not have a browser installed.

Let’s see an example where we download the HTML code of a website to a file using the command below.

curl -o teste.html https://simplificandoredes.com
  • -o” : This option allows you to specify the name of the file.
  • teste.html“: This is the name we assigned to the file that will store the page downloaded from the URL.
  • https://simplificandoredes.com: This is the URL (web address) you want to access. You can replace it with another URL.

Checking the Header of a Web Page with curl

Now we will show how the curl command can help check the header of a page.

Checking the header of a page can be useful because we can obtain relevant information just by analyzing the header.

To view a page’s header with curl, we will use the command below.

curl -I https://simplificandoredes.com
  • -I” : This option allows you to obtain header information from the page.
  • https://simplificandoredes.com: This is the URL (web address) you want to access. You can replace it with another URL.

Checking Your Public IP with curl

Another interesting use of curl is to obtain your public IP. In this case, we can use curl to access websites that provide the user’s public IP.

Below is an example of using curl to check the public IP.

curl ifconfig.me

These were just a few examples of using curl, and there is obviously much more to explore about this command. Let me know if you want to see more material on curl.

See more:

What is CGNAT ?

Tutorial: How to use WHOIS and RDAP

How to Set Up a Postfix and Dovecot Email Server on Linux: A Step-by-Step Guide

Tutorial how to Install and configure VNC on Ubuntu

Build Your Own DNS Server: A Step-by-Step Guide using BIND9

Juliana Mascarenhas

Data Scientist and Master in Computer Modeling by LNCC.
Computer Engineer