Linux · March 25, 2023 0

Curl is a versatile command-line tool for transferring data to or from a server

Table of Content

Curl is a versatile command-line tool for transferring data to or from a server, using various protocols such as HTTP, FTP, SMTP, and more. Here are some useful curl commands and options to help you get started:

  1. Sending a GET request: To send a GET request to a URL, simply run:
curl <URL>

For example, to fetch the contents of a web page:

  1. Sending a POST request: To send a POST request with data, use the -d option:
curl -d "param1=value1&param2=value2" -X POST <URL>

For example, to submit a form with two parameters to a URL:

curl -d "username=johndoe&password=secret" -X POST
  1. Specifying request headers: To specify custom request headers, use the -H option:
curl -H "Accept: application/json" <URL>

For example, to request JSON data:

curl -H "Accept: application/json"
  1. Downloading a file: To download a file from a URL, use the -O (capital letter O) option:
curl -O <URL>

For example, to download a file named

curl -O
  1. Following redirects: By default, curl does not follow redirects. To follow redirects automatically, use the -L option:
curl -L <URL>

These are just a few examples of what you can do with curl. For more information, check out the curl manual by running man curl in a terminal.

To check the headers of a response using curl

To check the headers of a response using curl, you can use the -I option to send a HEAD request and print out the headers. For example, to check the headers of a web page:

curl -I

This will send a HEAD request to the URL and print out the response headers, without downloading the content of the page. You can also use the -i option to include the response headers in the output of the request with the response body as well.

Additionally, you can use the -v option to enable verbose mode, which will print out more information, including the request headers and the response status code.

curl -v

This will print out the full request and response headers, along with the response body.

To install curl on Linux

To install curl on Linux, you can use the package manager for your distribution. For example, on Ubuntu, you can run:

sudo apt-get install curl

On Fedora, you can run:

sudo dnf install curl

On CentOS, you can run:

sudo yum install curl

On Arch Linux, you can run:

sudo pacman -S curl

To install curl on Windows, you can download the executable from the official website and follow the installation instructions. Alternatively, you can use a package manager like Chocolatey to install curl:

choco install curl

I hope this helps!

%d bloggers like this: