"curl" Command

Learn all about curl command

HOME

Curl is a command line tool for doing all sorts of URL manipulations and transfers. cURL supports various protocols like, DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP.

root:~# man curl
          
Curl is not written to do everything for you. It makes the requests, it gets the data, it sends data and it retrieves the information.

Using curl's option --verbose (-v as a short option) will display that what kind of commands curl sends to the server, as well as a few additional informational texts. This will help in debugging.
root:~# curl -v http://candidinformation.com/
* Hostname was NOT found in DNS cache
*   Trying 166.62.6.49...
* Connected to candidinformation.com (166.62.6.49) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: candidinformation.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 20 Sep 2017 18:12:08 GMT
* Server Apache/2.4.25 is not blacklisted
< Server: Apache/2.4.25
< Last-Modified: Mon, 12 Jun 2017 07:18:14 GMT
< ETag: "49a059d-13b5-551be1f4c2293"
< Accept-Ranges: bytes
< Content-Length: 5045
< Vary: Accept-Encoding,User-Agent
< Content-Type: text/html
<
<!DOCTYPE html>
<html lang="en">
.
.
.
</html>

Sometimes even --verbose is not enough then --trace and --trace-ascii offer even more details as they show EVERYTHING curl sends and receives.

--trace [filename] will save a full trace in the given file name. User can also give '-' instead of a file name to get it passed to stdout.

root:~# curl --trace dump http://www.candidinformation.com/
When completed, there is a 'dump' file that generated and first 20 lines of the dump looks like:
root:~# head -n 20 dump
== Info: Hostname was NOT found in DNS cache
== Info:   Trying 166.62.6.49...
== Info: Connected to www.candidinformation.com (166.62.6.49) port 80 (#0)
=> Send header, 89 bytes (0x59)
0000: 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a GET / HTTP/1.1..
0010: 55 73 65 72 2d 41 67 65 6e 74 3a 20 63 75 72 6c User-Agent: curl
0020: 2f 37 2e 33 35 2e 30 0d 0a 48 6f 73 74 3a 20 77 /7.35.0..Host: w
0030: 77 77 2e 63 61 6e 64 69 64 69 6e 66 6f 72 6d 61 ww.candidinforma
0040: 74 69 6f 6e 2e 63 6f 6d 0d 0a 41 63 63 65 70 74 tion.com..Accept
0050: 3a 20 2a 2f 2a 0d 0a 0d 0a                      : */*....
<= Recv header, 17 bytes (0x11)
0000: 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK.
0010: 0a                                              .
<= Recv header, 37 bytes (0x25)
0000: 44 61 74 65 3a 20 53 75 6e 2c 20 31 37 20 53 65 Date: Sun, 17 Se
0010: 70 20 32 30 31 37 20 31 34 3a 30 36 3a 35 38 20 p 2017 14:06:58
0020: 47 4d 54 0d 0a                                  GMT..
== Info: Server Apache/2.4.25 is not blacklisted
<= Recv header, 23 bytes (0x17)
0000: 53 65 72 76 65 72 3a 20 41 70 61 63 68 65 2f 32 Server: Apache/2
Every single sent and received byte gets displayed individually in hexadecimal numbers so if use thinks that hexadecimal isn't helping then --trace-ascii can be used.

--trace-ascii [filename] will save a full trace in the given file name. User can also give '-' instead of a file name to get it passed to stdout.

root:~# curl --trace-ascii dump http://www.candidinformation.com/
When completed, there is a 'dump' file that generated and first 20 lines of the dump looks like:
root:~# head -n 20 dump
== Info: Hostname was NOT found in DNS cache
== Info:   Trying 166.62.6.49...
== Info: Connected to www.candidinformation.com (166.62.6.49) port 80 (#0)
=> Send header, 89 bytes (0x59)
0000: GET / HTTP/1.1
0010: User-Agent: curl/7.35.0
0029: Host: www.candidinformation.com
004a: Accept: */*
0057:
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 37 bytes (0x25)
0000: Date: Sun, 17 Sep 2017 14:12:40 GMT
== Info: Server Apache/2.4.25 is not blacklisted
<= Recv header, 23 bytes (0x17)
0000: Server: Apache/2.4.25
<= Recv header, 46 bytes (0x2e)
0000: Last-Modified: Mon, 12 Jun 2017 07:18:14 GMT
<= Recv header, 36 bytes (0x24)
0000: ETag: "49a059d-13b5-551be1f4c2293"

--trace-time options will prefixes all verbose/trace outputs with a high resolution timer for when the line is printed. It works with regular -v/--verbose option as well as with --trace/--trace-ascii

root:~# curl -v --trace-time http://www.candidinformation.com/
14:24:36.467692 * Hostname was NOT found in DNS cache
14:24:36.496278 *   Trying 166.62.6.49...
14:24:36.690067 * Connected to www.candidinformation.com (166.62.6.49) port 80 (#0)
14:24:36.690122 > GET / HTTP/1.1
14:24:36.690122 > User-Agent: curl/7.35.0
14:24:36.690122 > Host: www.candidinformation.com
14:24:36.690122 > Accept: */*
14:24:36.690122 >
14:24:36.891372 < HTTP/1.1 200 OK
14:24:36.891416 < Date: Sun, 17 Sep 2017 14:24:36 GMT
14:24:36.891442 * Server Apache/2.4.25 is not blacklisted
14:24:36.891464 < Server: Apache/2.4.25
14:24:36.891488 < Last-Modified: Mon, 12 Jun 2017 07:18:14 GMT
14:24:36.891511 < ETag: "49a059d-13b5-551be1f4c2293"
14:24:36.891534 < Accept-Ranges: bytes
14:24:36.891557 < Content-Length: 5045
14:24:36.891580 < Vary: Accept-Encoding,User-Agent
14:24:36.891603 < Content-Type: text/html