cURL - ArchWiki

Jump to content
From ArchWiki

cURL is a command line tool and library for transferring data with URLs. The command supports a number of different protocols, including HTTP, HTTPS, FTP, SCP, and SFTP. It is also designed to work without user interaction, like in scripts.

## Installation

Install the curl package.

## Usage

### Downloading

A common use case for cURL is to download the resource to a specified file:

    $ curl -o file name URL

If the URL contains the file name, you can save the resource directly to a file of that name:

    $ curl -O URL

Similarly, you can use `-J` to accept a hint from an HTTP server (from the `Content-Disposition` header) for what the file should be named. If combined with `-O`, curl will use the file name specified by the URL if the HTTP server does not return a file name hint in its response.

Alternatively you can print the resource to stdout by omitting the output options:

    $ curl URL

### HTTP POST

You can use cURL to make HTTP POST requests:

    $ curl -d 'request body' URL

If the request body cannot fit on the command line, cURL can read it from a file:

    $ curl -d @file name URL

Sometimes, you may need to specify a custom value for the `Content-Type` header (cURL's default is `application/x-www-form-urlencoded`). You can do this with `-H`. For example, if you wanted to make a POST request with a JSON body:

    $ curl -d 'json body' -H 'Content-Type: application/json' URL

note that curl also has a option to write post data in json and change those headers automatically: `--json`:

    $ curl --json '{"key":"value"}' URL

## Tips and tricks

### Following redirects

To follow redirects (e.g. an HTTP to HTTPS redirect):

    $ curl -L URL

### Show download errors

By default curl would ignore errors (e.g. when downloading to a file, if there is a error curl would not notify you, and the file would be created empty) so use `--fail` to make it show a message on error:

    $ curl --fail URL

### Compression

If you want to transfer the data compressed, (e.g. in situations where bandwidth is more limited than CPU,curl would download the data compressed then uncompressed it after the downlod):

    $ curl --compressed URL

### ProgressBar

curl has option to a normal ProgressBar when it download files (e.g. `[##### ] 80%` )

    $ curl '-#' URL

### Globbing

You can also use globing in curl:

    $ curl "example.com/images/[1-9].png"
    $ curl "example.com/{first_page,second_page,third_page}"

## config file

curl also search for a config file called `.curlrc` in home directory and in `$XDG_CONFIG_HOME`. you can just put the command line argument you want to use with curl by default, for example :

    $HOME/.curlrc

    # this is a comment, the next line would be the option for progressbar:
    -#
    # to make curl always compress:
    --compressed
    # or just
    compressed

## See also

- Wikipedia:cURL
- Everything curl - Extensive guide to using cURL
- curl(1)

Category:

- Download utilities