
curl - submit HTTP requests and download files
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.
Check TCP Port Connectivity with curl
Here’s a quick video from UnixTutorial.TV showing how you can test TCP ports with curl
Test if Webpage Exists
Simply specify a URL and curl command will attempt a download:
{% highlight console %} $ 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 {% endhighlight %}
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
:
{% highlight console %} $ 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 {% endhighlight %}
If we check now, /tmp/webpage.html
file exists and contains whatever my main webpage did at the time of the download:
{% highlight console %} $ ls -la /tmp/webpage.html -rw-r–r– 1 greys wheel 56148 10 Jul 12:53 /tmp/webpage.html {% endhighlight %}