• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

curl Command Examples in Linux

by admin

Web browsers aren’t the only Linux programs that visit websites. The programs curl and wget can download web pages and other web content with a single command, without touching a browser. By default, curl prints its output to stdout, and wget saves its output to a file (after printing lots of diagnostic messages).

Syntax

The syntax of the curl commands is:

# curl [options] {URL}

curl Command Examples

1. Download the contents of a URL to a file:

# curl http://example.com --output filename

2. Download a file, saving the output under the filename indicated by the URL:

# curl --remote-name http://example.com/filename

3. Download a file, following location redirects, and automatically continuing (resuming) a previous file transfer and return an error on server error:

# curl --fail --remote-name --location --continue-at - http://example.com/filename

4. Send form-encoded data (POST request of type `application/x-www-form-urlencoded`). Use `–data @file_name` or `–data @’-‘` to read from STDIN:

# curl --data 'name=bob' http://example.com/form

5. Send a request with an extra header, using a custom HTTP method:

# curl --header 'X-My-Header: 123' --request PUT http://example.com

6. Send data in JSON format, specifying the appropriate content-type header:

# curl --data '{"name":"bob"}' --header 'Content-Type: application/json' http://example.com/users/1234

7. Pass a username and password for server authentication:

# curl --user myusername:mypassword http://example.com

8. Pass client certificate and key for a resource, skipping certificate validation:

# curl --cert client.pem --key key.pem --insecure https://example.com

Difference between curl and wget

While wget and curl perform the same basic function, there are some key differences:

  • wget is a command-line utility only, whereas curl is implemented using the cross-platform libcurl library and is therefore more easily ported to other systems.
  • wget can download files recursively, whereas curl cannot.
  • curl supports many more network protocols than wget, which only supports HTTP/S and FTP.
  • wget is better suited for straightforward downloading of files from a web server, whereas curl is better suited to building and managing more complex requests and responses from web servers.

Filed Under: Linux

Some more articles you might also be interested in …

  1. ghcup: Haskell toolchain installer
  2. circup: The CircuitPython library updater
  3. v4l2-ctl: command not found
  4. qsub Command Examples in Linux
  5. How to disable auto completion (tab completion) in bash shell
  6. kwriteconfig5 Command Examples in Linux
  7. hn Command Examples
  8. lvs: command not found
  9. jhsdb Command Examples
  10. check-language-support Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright