Fundamentals 7 min read

Mastering curl: Essential Commands, Options, and Real‑World Examples

This guide explains what curl is, why it’s useful for network debugging and automation, shows how to install it on common Linux distributions, describes its syntax, lists the most frequently used options for requests, data transfer, output handling, debugging, and provides practical command‑line examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering curl: Essential Commands, Options, and Real‑World Examples

Overview

curl (Client URL) is a command‑line tool and library for transferring data over URLs. It supports more than 100 protocols, including HTTP/HTTPS, FTP, SMTP, POP3, RTSP and DICT. curl is lightweight, cross‑platform (Linux, Windows, macOS) and script‑friendly, making it suitable for API testing, file transfer and network diagnostics.

Typical Use Cases

API debugging – test RESTful endpoints (GET, POST, PUT, DELETE, …).

File transfer – download or upload files via FTP, SCP, SFTP, etc.

Network diagnosis – inspect server response status and headers.

Data collection – fetch web pages (respect robots.txt).

Scripting – embed network requests in shell or Python scripts.

Installation

# Debian/Ubuntu
apt install -y curl
# CentOS/RHEL
yum install -y curl

Basic Syntax

curl [options] [url]
options

are command‑line flags; url is the target resource.

Commonly Used Options

Request Control

-X, --request <method>

– specify HTTP method (GET, POST, PUT, DELETE, …). -H, --header <header> – add custom request headers; can be repeated. -d, --data <data> – send POST data (application/x‑www‑form‑urlencoded). -b, --cookie <name=value|file> – send cookies.

Data Transfer

-o, --output <file>

– write response body to a file. -O, --remote-name – download using the remote file name. -F, --form <name=content> – submit multipart/form‑data (file upload). -T, --upload-file <file> – upload a file with PUT or POST.

Output & Debugging

-v, --verbose

– show detailed request/response information. -s, --silent – suppress progress bar (errors still shown). -S, --show-error – display errors when used with -s. -D, --dump-header <file> – save response headers to a file.

Advanced Options

--proxy <host:port>

– route traffic through an HTTP or SOCKS5 proxy. -k, --insecure – skip HTTPS certificate verification (useful for testing). --limit-rate <speed> – throttle transfer speed (e.g., 100k for 100 KB/s). --retry <num> – number of retries on transient failures. --range <byte-range> – request a specific byte range for resumable downloads.

Practical Examples

GET request with custom Host header:

curl -H "Host: fake.example.com" http://192.0.2.1

Download a page to a specific file:

curl -o filename.html https://example.com/page.html

Download using remote filename: curl -O https://example.com/file.zip POST form data:

curl -d "name=John&age=30" https://api.example.com/submit

Upload a file via FTP:

curl -T report.pdf ftp://ftp.example.com/upload/

Follow redirects automatically: curl -L http://example.com Save response headers to a file:

curl -D headers.txt https://www.example.com

References

Official documentation: https://curl.se/docs/

GitHub repository: https://github.com/curl/curl

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DevOpsLinuxHTTPcURLcommand-line
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.