Skip to content
curl Command in Linux — Transfer Data with Examples

curl Command in Linux — Transfer Data with Examples

DodaTech Updated Jun 20, 2026 6 min read

curl is a Linux command-line tool for transferring data using network protocols — HTTP, HTTPS, FTP, SFTP, SMTP, and many more. It’s the Swiss Army knife of network data transfer.

What You’ll Learn

By the end of this tutorial, you’ll know how to make GET and POST requests, set custom headers, save output to files, follow redirects, authenticate, enable verbose debugging, upload files, resume interrupted downloads, and manage cookies.

Why curl Matters

curl is everywhere — API testing, downloading files, checking HTTP headers, automating web interactions, and troubleshooting servers. Durga Antivirus Pro uses curl to download virus definition updates, and Doda Browser uses it internally for network requests.

curl Learning Path

    flowchart LR
  A[Essential Commands] --> B[Networking Commands]
  B --> C[curl Command<br/>You are here]
  C --> D[jq Command]
  D --> E[API Testing & Automation]
  style C fill:#f90,color:#fff
  
Prerequisites: Basic Linux command-line skills. Review essential Linux commands and networking commands.

Syntax Overview

curl [options] URL
OptionDescription
-X METHODHTTP method (GET, POST, PUT, DELETE)
-d "data"Send POST data
-H "Header: value"Custom HTTP header
-o fileSave output to file
-OSave with remote filename
-LFollow redirects
-u user:passBasic authentication
-vVerbose output
-F "name=@file"Upload file as multipart form
-C -Resume interrupted download
-b cookies.txtSend cookies from file
-c cookies.txtWrite cookies to file

10 Practical Examples

We’ll use https://httpbin.org — a free HTTP testing service — for most examples.

1. GET Request

Simple HTTP GET:

curl https://httpbin.org/get
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/8.4.0"
  },
  "origin": "203.0.113.42",
  "url": "https://httpbin.org/get"
}

2. POST Data

Send form data with POST:

curl -X POST -d "name=Alice&role=admin" https://httpbin.org/post
{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "name": "Alice",
    "role": "admin"
  },
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "json": null,
  "url": "https://httpbin.org/post"
}

Send JSON data:

curl -X POST -H "Content-Type: application/json" \
     -d '{"name":"Alice","role":"admin"}' \
     https://httpbin.org/post
{
  "data": "{\"name\":\"Alice\",\"role\":\"admin\"}",
  "headers": {
    "Content-Type": "application/json"
  },
  "json": {
    "name": "Alice",
    "role": "admin"
  }
}

3. Custom Headers

Set the User-Agent and Authorization header:

curl -H "User-Agent: DodaBrowser/1.0" \
     -H "Authorization: Bearer token123" \
     https://httpbin.org/headers
{
  "headers": {
    "Authorization": "Bearer token123",
    "User-Agent": "DodaBrowser/1.0",
    "Host": "httpbin.org"
  }
}

4. Save Output to File

Download a file and save with a specific name:

curl -o index.html https://example.com

No output shown (saved to file). Check it:

ls -la index.html
head -3 index.html
-rw-r--r-- 1 alice alice 1256 Jun 20 10:00 index.html
<!doctype html>
<html>
<head>

Download and save with the remote filename:

curl -O https://example.com/file.zip

5. Follow Redirects

Without -L, curl shows the redirect page:

curl -I https://httpbin.org/redirect/1
HTTP/2 302
Location: /relative-redirect/1

With -L, it follows all redirects:

curl -L -o /dev/null -w "%{http_code}" https://httpbin.org/redirect/3
200

6. Authentication

Basic HTTP authentication:

curl -u alice:secretpass https://httpbin.org/basic-auth/alice/secretpass
{
  "authenticated": true,
  "user": "alice"
}

With wrong password:

curl -u alice:wrongpass https://httpbin.org/basic-auth/alice/secretpass
Unauthorized

7. Verbose Debugging

See every step of the request/response:

curl -v https://example.com 2>&1 | head -20
* Host example.com:80 was resolved.
* IPv6: 2606:2800:220:1:248:1893:25c8:1946
* IPv4: 93.184.215.14
*   Trying 93.184.215.14:80...
* Connected to example.com (93.184.215.14) port 80
> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
< Server: EC2 (amz/54)
<

8. Upload Files

Upload a file as multipart form data:

curl -F "file=@/home/alice/report.pdf" \
     -F "description=Monthly report" \
     https://httpbin.org/post
{
  "files": {},
  "form": {
    "description": "Monthly report"
  },
  "files": {
    "file": "binary content..."
  }
}

9. Resume Interrupted Download

Download a file, interrupt it, then resume:

# Start download
curl -o bigfile.iso https://example.com/largefile.iso
# Press Ctrl+C to interrupt

# Resume from where it stopped
curl -C - -o bigfile.iso https://example.com/largefile.iso
** Resuming transfer from byte 4521984
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 50.0M  100 50.0M    0     0  5.2M      0  0:00:09  0:00:09 --:--:-- 5.2M

10. Cookies

Save cookies from a server response:

curl -c cookies.txt https://httpbin.org/cookies/set?session_id=abc123
cat cookies.txt
# Netscape HTTP Cookie File
httpbin.org	FALSE	/	FALSE	0	session_id	abc123

Send cookies with a request:

curl -b cookies.txt https://httpbin.org/cookies
{
  "cookies": {
    "session_id": "abc123"
  }
}

Common Use Cases

Check HTTP Status Code Only

curl -o /dev/null -s -w "%{http_code}" https://example.com

Test API Endpoint

curl -s https://api.github.com/repos/curl/curl | jq '.stargazers_count'

Download with Rate Limiting

curl --limit-rate 500K -O https://example.com/bigfile.zip

Check SSL Certificate Details

curl -vI https://example.com 2>&1 | grep -i "certificate\|subject\|issuer"

Common Mistakes

1. Forgetting -L for Redirects

Many URLs redirect (301/302). Without -L, curl returns the redirect page, not the final content. Always use -L when you want the actual resource.

2. Not Quoting Data with Special Characters

curl -d '{"key": "value"}' — the single quotes prevent shell expansion. Without them, the shell may interpret {, }, and other characters.

3. Confusing -d and -F

-d sends URL-encoded form data. -F sends multipart form data (for file uploads). Use -d for simple API POSTs and -F when uploading files.

4. Ignoring SSL Errors

curl -k skips certificate validation. Only use this for testing. In production, fix the SSL issue instead.

Practice Questions

1. How do you download a file and save it with the original filename?

curl -O https://example.com/file.zip

2. What does curl -I https://example.com do?

It sends a HEAD request, showing only the HTTP headers without the response body.

3. How do you send a POST request with JSON data?

curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL

4. What’s the difference between -o and -O?

-o file saves output to a specified filename. -O saves using the filename from the URL.

5. Challenge: Write a curl command that tests if a URL returns 200, following redirects, with a 10-second timeout.

curl -L -o /dev/null -s -w "%{http_code}" --max-time 10 https://example.com

Mini Project: Website Health Check Script

#!/bin/bash
# health_check.sh — Check multiple URLs for availability
# Usage: ./health_check.sh urls.txt

URLS_FILE="${1:-urls.txt}"

if [ ! -f "$URLS_FILE" ]; then
    echo "Error: File not found: $URLS_FILE"
    echo "Create a file with one URL per line."
    exit 1
fi

echo "=== Website Health Check ==="
echo "Date: $(date)"
echo ""

while IFS= read -r url || [ -n "$url" ]; do
    [ -z "$url" ] && continue
    
    http_code=$(curl -L -o /dev/null -s -w "%{http_code}" --max-time 10 "$url" 2>/dev/null)
    time_total=$(curl -L -o /dev/null -s -w "%{time_total}" --max-time 10 "$url" 2>/dev/null)
    
    if [ "$http_code" = "200" ]; then
        status="✓ UP"
    else
        status="✗ DOWN (HTTP $http_code)"
    fi
    
    printf "%-40s %-15s %5ss\n" "$url" "$status" "$time_total"
done < "$URLS_FILE"

Expected output:

=== Website Health Check ===
Date: Sat Jun 20 10:00:00 UTC 2026

https://example.com                ✓ UP             0.234s
https://httpbin.org/get            ✓ UP             0.567s
https://nonexistent.domain.test    ✗ DOWN (HTTP 000)  0.000s

FAQ

What protocols does curl support?
HTTP, HTTPS, FTP, SFTP, SCP, LDAP, SMTP, POP3, IMAP, GOPHER, DICT, TELNET, and more. See curl --version for your build.
What’s the difference between curl and wget?
curl supports more protocols, has better API testing features (headers, methods, data), and is more scriptable. wget is simpler for recursive downloads and has built-in retry logic. For API work, use curl.
How do I ignore SSL certificate errors?
Use -k or --insecure. Only do this in development environments. In production, fix the certificate issue.
Can curl handle HTTP/2?
Yes, with --http2. Most modern servers support HTTP/2, which is faster than HTTP/1.1 for concurrent requests.

What’s Next

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro