curl - submit HTTP requests and download files

curl curl command

curl is a super popular command line tool for downloading files over the network via various network protocols like HTTP or FTP. It also supports submitting GET/POST requests via HTTP, making it very useful for API development and debugging.

curl is based on a libcurl library, part of the same project, which makes it more suitable for use in programming various applications.

Test if Webpage Exists

Simply specify a URL and curl will attempt a download:

$ curl -o /dev/null https://www.unixtutorial.org
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 56148 0 56148 0 0 151k 0 --:--:-- --:--:-- --:--:-- 151k

In this example, we’re using the -o (output) option to redirect output (page contents) into /dev/null - we basically discard the contents as we’re not interested in it just yet.

Download File or Webpage into a File

In this example, we’re using the same -o option but specify a filename instead of /dev/null - thus making curl command save the URL content into a file named /tmp/webpage.html:

$ curl -o /tmp/webpage.html https://www.unixtutorial.org
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 56148 0 56148 0 0 151k 0 --:--:-- --:--:-- --:--:-- 151k

If we check now, /tmp/webpage.html file exists and contains whatever my main webpage did at the time of the download:

$ ls -la /tmp/webpage.html
-rw-r--r-- 1 greys wheel 56148 10 Jul 12:53 /tmp/webpage.html

See also




Keep Learning

Follow me on Facebook, Twitter or Telegram:
Recommended
I learn with Educative: Educative
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets