curl is the Swiss Army knife of URL fetching. It supports HTTP, HTTPS, FTP, SFTP, SMTP, IMAP, LDAP, Gopher, and a long list of others; it can send POST data, upload files, follow redirects, include headers, use cookies, maintain sessions, and speak JSON over REST APIs. It has been actively developed by Daniel Stenberg since 1997 and is found on nearly every Linux and embedded system.
curl https://example.com # print response body
curl -o file.zip https://example.com/file.zip # save to file
curl -L url # follow redirects
curl -I url # HEAD request
curl -H 'Accept: application/json' url # custom header
curl -X POST -d '{"key":"val"}' \
-H 'Content-Type: application/json' url # POST JSON
curl -s url | jq . # silent + pipe to jq
For API work, curl paired with jq for JSON processing is a complete REST client in two commands. For debugging, curl -v or curl --trace-ascii - shows every request and response header, invaluable when a connection is behaving oddly. An alternative, wget, is better at recursive downloads; curl is better at everything else.
Related terms: wget
Discussed in:
- Chapter 12: Networking — File Transfer: scp, rsync, curl, wget
Also defined in: Textbook of Linux