The Linux curl command can do a whole lot more than download files. Find out what curl is capable of, and when you should use it instead of wget.
curl vs. wget : What’s the Difference?
People often struggle to identify the relative strengths of the wget and curl commands. The commands do have some functional overlap. They can each retrieve files from remote locations, but that’s where the similarity ends.
wget is a fantastic tool for downloading content and files. It can download files, web pages, and directories. It contains intelligent routines to traverse links in web pages and recursively download content across an entire website. It is unsurpassed as a command-line download manager.
curl satisfies an altogether different need. Yes, it can retrieve files, but it cannot recursively navigate a website looking for content to retrieve. What curl actually does is let you interact with remote systems by making requests to those systems, and retrieving and displaying their responses to you. Those responses might well be web page content and files, but they can also contain data provided via a web service or API as a result of the “question” asked by the curl request.
And curl isn’t limited to websites. curl supports over 20 protocols, including HTTP, HTTPS, SCP, SFTP, and FTP. And arguably, due to its superior handling of Linux pipes, curl can be more easily integrated with other commands and scripts.
The author of curl has a webpage that describes the differences he sees between curl and wget.
How to Install curl
Out of the computers used to research this article, Fedora 31 and Manjaro 18.1.0 had curl already installed. curl had to be installed on Ubuntu 18.04 LTS. On Ubuntu, run this command to install it:
sudo apt-get install curl
The curl Version
The --version option makes curlreport its version. It also lists all the protocols that it supports.
curl --version
Retrieving a Web Page with curl
If we point curl at a web page, it will retrieve it for us.
curl https://www.bbc.com
But its default action is to dump it to the terminal window as source code.
If you don’t tell curl
you want something stored as a file, it will always dump it to the terminal window. If the file it is retrieving is a binary file, the outcome can be unpredictable. The shell may try to interpret some of the byte values in the binary file as control characters or escape sequences.
Saving Data to a File
Let’s tell curl to redirect the output into a file: