• 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. abroot Command Examples in Linux
  2. sar Command Examples in Linux
  3. How to Install Cockpit’s Web Console in CentOS/RHEL 8
  4. jpegtran: command not found
  5. cargo doc: Build and view Rust package documentation offline
  6. How to Permanently set the ethtool settings in CentOS/RHEL 6
  7. mktemp: command not found
  8. fio: Flexible I/O tester
  9. a2ensite: command not found
  10. mesg Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright