Linux Terminal Command: curl

The curl command is an essential tool in Network Utilities. In this tutorial, we will explore what curl does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The curl command downloads or uploads data using protocols like HTTP, HTTPS, FTP, and SFTP. It is highly configurable and scriptable.


Common Options & Syntax

curl [options] [arguments]

Here are the most common flags used with curl:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
curl https://api.ipify.org

What it does: Fetches raw API text from a server and prints it directly to stdout.


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
curl -x GET -H 'Authorization: Bearer token' -d '{"key":"val"}' -o res.json https://api.com

What it does: Sends a GET request, adds a custom header (-H), transmits JSON parameters (-d), and writes the response to ‘res.json’ (-o).


⚙️ Warning & Common Pitfalls

[!WARNING] By default, curl does not follow HTTP redirects. You must pass the -L flag to follow redirects to new locations.


Here are some related posts on cli_tty1 you might want to check out: