Lesson 84: curl Command
In this lesson, you'll learn how to use the curl command to download and upload files, query HTTP headers, and interact with web servers in Linux.
The curl command downloads files that are served with FTP, HTTP, SCP, IMAP, and other various supported protocols.
It's an amalgamation of the words World Wide Web, and it is used in Unix/Linux systems to download files and packages on the Linux terminal.
It is a command-line tool for transferring data to and from a server using various types of requests.
It's an alternative to downloading files, other than using the wget command.
Let's discuss some examples of the curl command to understand its usage in a better way.
curl Command Syntax
$ curl [OPTIONS] [URL]
curl Command Options
| Option | Description |
|---|---|
-V or --version |
Display version, supported protocols, and features |
-O |
Download a file and save it with the same remote filename |
-o FILE |
Download a file and save it with a custom filename |
-C - |
Resume an interrupted download |
-x PROXY:PORT |
Use a proxy server |
-U USER:PASS |
Proxy authentication credentials |
-I |
Query HTTP headers only (HEAD request) |
--data |
Send POST data with the request |
-u USER:PASS |
FTP/HTTP authentication credentials |
-T FILE |
Upload a file to an FTP server |
--user-agent |
Specify a custom user agent string |
--cookie-jar FILE |
Save cookies from a website to a file |
--cookie FILE |
Send stored cookies with a request |
--resolve HOST:PORT:ADDR |
Override DNS resolution for a specific host |
--limit-rate RATE |
Limit the download rate (e.g. 100K) |
1. View curl Version
The -V or --version options will not only provide the version information but also detail the supported protocols and features within your current version.
$ curl --version
curl 8.3.0 (x86_64-pc-linux-gnu) libcurl/8.3.0 OpenSSL/3.1.2 zlib/1.2.13 brotli/1.0.9
Release-Date: 2023-09-13
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
2. Download a File
If you want to download a file, you can use curl with the -O or -o options.
The former will save the file in the current working directory with the same name as in the remote location, whereas the latter allows you to specify a different filename and/or location.
$ curl -O http://yourdomain.com/yourfile.tar.gz # Save as yourfile.tar.gz
$ curl -o newfile.tar.gz http://yourdomain.com/yourfile.tar.gz # Save as newfile.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3565k 100 3565k 0 0 689k 0 0:00:05 0:00:05 --:--:-- 701k