H
10Corp Premium Hosting

The curl Command in Linux

Last Updated: 2025-01-01 2 min read

Overview

curl (Client URL) is a command-line tool for transferring data using various protocols, most commonly HTTP and HTTPS. It’s invaluable for testing web applications, checking server responses, and downloading files directly from the terminal.

Basic Syntax

curl [options] [URL]

Common Usage Examples

Fetch a webpage

curl https://example.com

This outputs the raw HTML to the terminal.

Download a file

curl -O https://example.com/backup.tar.gz

-O saves the file with its original filename. To specify a custom name:

curl -o myfile.tar.gz https://example.com/backup.tar.gz

Follow redirects

Many URLs redirect (301/302). By default, curl does not follow them:

curl -L https://example.com

-L tells curl to follow redirects until it reaches the final destination.

Checking HTTP Headers

View response headers only

curl -I https://example.com

Sample output:

HTTP/2 200
content-type: text/html; charset=UTF-8
server: nginx
cache-control: max-age=3600

View headers AND body

curl -i https://example.com

This is useful for debugging caching, content-type, or security headers.

Making POST Requests

Send form data

curl -X POST -d "username=admin&password=secret" https://example.com/login

Send JSON data

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"name": "John", "email": "john@example.com"}' \
  https://api.example.com/users

Useful Flags Reference

FlagDescription
-OSave file with original filename
-o FILESave output to a specified file
-LFollow redirects
-IFetch headers only (HEAD request)
-iInclude response headers in output
-X METHODSpecify HTTP method (GET, POST, PUT, DELETE)
-d DATASend data in a POST request
-H HEADERAdd a custom header
-u user:passHTTP basic authentication
-kAllow insecure SSL connections (skip certificate verification)
-sSilent mode — suppress progress bar
-vVerbose — show full request/response details
-w FORMATWrite output format after completion
--max-time NSet maximum time in seconds for the request
-C -Resume a partially downloaded file

Practical Hosting Examples

Test if your site is responding

curl -sI https://yourdomain.com | head -5

Check your server’s external IP

curl ifconfig.me

Measure response time

curl -o /dev/null -s -w "Time: %{time_total}s\nHTTP Code: %{http_code}\n" https://yourdomain.com

Download and extract in one step

curl -L https://example.com/archive.tar.gz | tar -xzf -

Test an API endpoint with authentication

curl -u apiuser:apikey https://api.example.com/v1/status

Check SSL certificate details

curl -vI https://yourdomain.com 2>&1 | grep -E "subject:|expire|issuer:"

Tips

  • Use -v (verbose) when debugging unexpected responses — it shows the full request and response cycle including headers and SSL handshake.
  • Combine -s (silent) with -o /dev/null when you only care about status codes or timing, not the body.
  • If you get SSL errors, don’t default to -k in production. Instead, investigate and fix the certificate issue.
Tags: ssh linux curl http networking

Still need help?

Our support team is available 24/7 to assist you.