What the hell is cURL?

cURL is an open source command line application tool that allows you to transfer data on HTTP, HTTP/2, FTP and many others. It is used by computers, cell phones, cars, tablets, IoT devices and many more.

On this article we are going to focus on using cURL to troubleshoot websites only.

Installation

Depending on the OS that you have the directions might be different so check your OS below:

cURL on Mac OS

You are very lucky. There is nothing to do, cURL is already installed with every Mac OS install and is available right from your Terminal or favorite SSH client (hint iTerm2).

cURL on Linux

Depending on the flavor of your Linux distribution below are the statements required to install cURL on your computer:

Debian, Ubuntu and similar

sudo apt-get update
sudo apt-get install curl

RHEL, Fedora, CentOS, Amazon Linux and similar

sudo yum install curl

SuSe Linux

sudo zypper in curl

Arch Linux

pacman -S libcurl

cURL on Windows 10

First you need to install Ubuntu’s BASH on the Windows computer. After you have finished installing it, then you can simply run the following commands:

sudo apt-get update
sudo apt-get install curl

Completed, now up to something more interesting!

Examples of usage

Download a file from HTTP

curl -O  https://salrocks.com/test.html

This command will download the file named test.html from the website salrocks.com. Below is an example for downloading the latest version of WordPress from their website:

curl -O https://wordpress.org/wordpress-4.9.2.zip

Partial downloads of document/pages/files

If you know your way around the terminal on Linux or MacOS computers, then you are most likely familiar with head and less which are to preview the first and last lines of a document. Well, cURL allows you to do just that. It comes pretty handy when there is a HUGE debug or error log that you need to see and you do not want to download the 1GB file. Use any of the examples below:

Getting the first 10 bytes and display them on screen:

curl -r 0-9 https://salrocks.com/error.log

If you want to send the output to file you can do something like this:

curl -r 0-9 https://salrocks.com/error.log > temp.txt

Pretty cool huh?

To Summarize

cURL is an extremely useful tool to use if you are a Developer, IT Pro, SysAdmin, Web Designer, etc; as it will help you to replicate requests done to servers without having to use a browser. It is extremely helpful when diagnosing issues with REDIRECTS and CACHING.

I am thinking of writing a tutorial about HTTP headers. What do you guys think?


Posted

in

, ,

by

Tags:

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments