In this tutorial, we are going to explain the main difference between the curl and wget commands in Linux with examples.
These two commands are very often used by system administrators and other Linux users on daily basis. Curl is a free and open-source utility that offers to transfer data between remote machines. Wget is also a free command line utility that offers transferring files using HTTP, HTTPS, FTP, and FTPS. Wget is a simple transfer utility, while curl offers so much more.
In this tutorial we are going to execute the commands on Ubuntu 22.04 but you can choose any Linux distro. Let’s get started!
What is Curl
Curl is a shortcut of client URL and is used for transferring data using various network protocols. Curl uses libcurl (free client-side URL transfer library) and supports every protocol that libcurl supports. Curl supports downloading and uploading via HTTP, HTPPS, FTP, IMAP, LDAP, and many more protocols. Curl let the user interact with the remote server and it can also work with proxies, support automatic decompression of compressed files and let us download multiple transfers in parallel.
Installing the Curl
Before we can use the curl command, we need to install it on our system. To do that execute the following command:
sudo apt-get install curl
After successfull installation, check the installed curl version.
curl -V
You should receive an output similar to this:
root@host:~# curl -V curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3 Release-Date: 2020-01-08 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
Some basic Curl commands
In this paragraph, we are going to show you some basic curl commands with examples.
Download a website and print the output in file.
curl https://google.com -o google.html
Once executed, you will receive the following output:
root@host:/opt# curl https://google.com -o google.html % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 220 100 220 0 0 750 0 --:--:-- --:--:-- --:--:-- 750
The -o flag is used to redirect the output to a file.
To return only the HTTP headers, execute the following command:
curl -I https://google.com
You should receive output similar to this:
root@host:/opt# curl -I https://google.com HTTP/2 301 location: https://www.google.com/ content-type: text/html; charset=UTF-8 date: Fri, 02 Sep 2022 13:22:23 GMT expires: Sun, 02 Oct 2022 13:22:23 GMT cache-control: public, max-age=2592000 server: gws content-length: 220 x-xss-protection: 0 x-frame-options: SAMEORIGIN alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
To check if HTTP/2 is supported, execute the command below:
curl -I --http2 https://domain.com
If the site does support HTTP/2, you will see HTTP/2.0 200 in the header instead of HTTP/1.1 200.
HTTP/2.0 200 OK Date: Fri, 02 Sep 2022 13:35:32 GMT Server: Apache/2.4.41 (Ubuntu) Content-Type: text/html;charset=UTF-8
What is Wget
Wget, the same as Curl is a free command line utility that offers to transfer files using the HTTP, HTTPS, FTP, and FTPS protocols. Wget retrieves the content recursively from the Web and supports recursive background downloads, mirrors, directories, and many more.
Installing the Wget
Before we can use the wget command, we need to install it on our system. To do that, execute the following command:
sudo apt-get install wget
After successfull installation, check the installed wget version.
wget -V
You should receive an output similar to this:
root@host:~# wget -V GNU Wget 1.20.3 built on linux-gnu. -cares +digest -gpgme +https +ipv6 +iri +large-file -metalink +nls +ntlm +opie +psl +ssl/openssl Wgetrc: /etc/wgetrc (system) Locale: /usr/share/locale
Some basic Wget commands
To download the website using wget execute the following command:
wget google.com
The html content of the website will be automatically saved in index.html file:
root@host:~# wget google.com --2022-09-02 19:52:49-- http://google.com/ Resolving google.com (google.com)... 172.217.0.174, 2607:f8b0:4009:803::200e Connecting to google.com (google.com)|172.217.0.174|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://www.google.com/ [following] --2022-09-02 19:52:49-- http://www.google.com/ Resolving www.google.com (www.google.com)... 172.217.4.196, 2607:f8b0:4004:c1b::63, 2607:f8b0:4004:c1b::93, ... Connecting to www.google.com (www.google.com)|172.217.4.196|:80... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: ‘index.html’ index.html [ <=> ] 13.67K --.-KB/s in 0.006s 2022-09-02 19:52:49 (2.36 MB/s) - ‘index.html’ saved [13993]
To download the web files in the background execute the wget command with -b parameter:
wget -b https://google.com
You will get the following message:
root@host:~# wget -b https://google.com Continuing in background, pid 226490. Output will be written to ‘wget-log’.
Differences between curl and wget commands
In the previous paragraph, we explained the curl and wget separately, and in this paragraph, we will summarize the main differences in a simple list.
- curl supports SOCKS, while wget does not.
- curl output is not redirected automatically in the file, while with wget it is.
- curl supports more protocols than wget
- wget supports recursive downloads while curl does not.
- wget does not perform transfer-encoded HTTP decompressions, while curl does.
- Curl provides the libcurl library
- wget requires gnulib installed.
Hopefully, our guide on the difference between Curl and get commands was of help to you. We would love to hear from you now:
Did we skip something essential or do you need a more detailed explanation about any of the steps?
What are some other topics or tutorials you would want us to delve into?
Please, feel free to share your thoughts in the comment section.