Command line options pass on information to curl about how you want it to
behave. Like you can ask curl to switch on verbose mode with the -v option:
-v is here used as a “short option”. You write those with the minus symbol and
a single letter immediately following it. Many options are just switches that
switches something on or changes something between two known states. They can
be used with just that option name. You can then also combine several
single-letter options after the minus. To ask for both verbose mode and that
curl follows HTTP redirects:
The command-line parser in curl always parses the entire line and you can put
the options anywhere you like; they can also appear after the URL:
curl http://example.com -Lv
Single-letter options are convenient since they are quick to write and use, but
as there are only a limited number of letters in the alphabet and there are
many things to control, not all options are available like that. Long option
names are therefore provided for those. Also, as a convenience and to allow
scripts to become more readable, most short options have longer name
aliases.
curl --verbose http://example.com
and asking for HTTP redirects as well using the long format looks like:
Not all options are just simple boolean flags that enable or disable
features. For some of them you need to pass on data, like perhaps a user name
or a path to a file. You do this by writing first the option and then the
argument, separated with a space. Like, for example, if you want to send an
arbitrary string of data in an HTTP POST to a server:
curl -d arbitrary http://example.com
and it works the same way even if you use the long form of the option:
When you use the short options with arguments, you can, in fact, also write the
data without the space separator:
curl -darbitrary http://example.com
Failing to use quotes, like if you would write the command line like this:
curl -A I am your father http://example.com
… will make curl only use ‘I’ as a user-agent string, and the following
strings, ‘am’, your, etc will instead all be treated as separate URLs since
they don’t start with to indicate that they’re options and curl only ever
handles options and URLs.
To make the string itself contain double quotes, which is common when you for
example want to send a string of JSON to the server, you may need to use
single quotes (except on Windows, where single quotes doesn’t work the same
way). Send the JSON string { "name": "Darth" }
:
curl -d '{ "name": "Darth" }' http://example.com
Or if you want to avoid the single quote thing, you may prefer to send the
data to curl via a file, which then doesn’t need the extra quoting. Assuming
we call the file ‘json’ that contains the above mentioned data:
curl -d @json http://example.com