The curl control is quite useful and flexible. The intent of the tool is to transfer data, without user interaction, to or from a server, using ane of the many supported protocols. It is that listing of protocols that helps curl manage to be and then flexible, as the control supports:

  • DICT
  • FILE
  • FTP
  • FTPS
  • GOPHER
  • HTTP
  • HTTPS
  • IMAP
  • IMAPS
  • LDAP
  • LDAPS
  • POP3
  • POP3S
  • RTMP
  • RTSP
  • SCP
  • SMB
  • SMBS
  • SMTP
  • SMTPS
  • TELNET
  • TFTP

That's a salubrious listing of possibilities. It as well ways curl tin can transfer just about any blazon of data. Curl can even display the source code of a URL. All of this without requiring user interaction (a crucial feature for scripting).

I want to show you lot how to make utilise of this command (ane you'll oft find in Linux howtos and scripts). I'll be demonstrating on Uncomplicated Bone, but the command works on nigh every available Linux distribution. Curl is also bachelor on macOS and Windows.

Come across: 20 quick tips to brand Linux networking easier (free PDF) (TechRepublic)

Installing curl

Your Linux distribution should have roll installed by default. If not, the installation is quite simple. On a Debian derivative, the installation command would exist:

sudo apt install curl

Yous can check the installation past issuing the control scroll –version. Yous should see the version number of the installed awarding (on my Elementary OS machine, information technology's 7.47.0).

Using ringlet

Allow'due south get-go run into how curl can exist used at its simplest. Say you desire to view the source of a spider web site. Nosotros'll utilise the curl site as an instance. Issue the command:

gyre https://gyre.haxx.se | less

You can now scroll through the HTML for that site (Figure A).

Effigy A

This is a great way to figure out how a site has been created or fifty-fifty troubleshooting your own sites.

Of course, that instance is quite limited. Permit's use curl to pull downward a file from a site. Allow'southward stick with the aforementioned example. Say yous desire to download the HTML for the whorl site to view later. For this, we'll use the -o switch like and so:

curl https://curl.haxx.se -o curl.html

The in a higher place command would download the HTML code from the curlicue site and salve information technology equally curl.html. Of form, curl isn't simply capable of downloading source HTML. Say you lot accept a file you desire to download from a site. Curl can handle this similar so:

curl http://SERVER_ADDRESS/FILENAME -o FILENAME

Where SERVER_ADDRESS is the URL of the server and FILENAME is the proper noun of the file to be downloaded. Say for case, you want to download the latest release of Ubuntu Server. That tin can exist done similar so:

curl http://releases.ubuntu.com/eighteen.04/ubuntu-18.04-live-server-amd64.iso -o ubuntu-server-18.04.iso

If that file is password protected, curl can handle that like so:

ringlet -u USERNAME:PASSWORD http://SERVER_ADDRESS -o FILENAME

Where:

  • USERNAME is the username on the server.
  • PASSWORD is the password for the user on the server.
  • FILENAME is the file to be downloaded.
  • SERVER_ADDRESS is the direct link to the file.

You can also use curl with an FTP server. Say you demand to download a file from an FTP server that happens to be password protected. The command for this would be:

scroll ftp://SERVER_ADDRESS/FILENAME -user USERNAME:Countersign -o FILENAME

Where:

  • SERVER_ADDRESS is the address of the FTP server.
  • FILENAME is the name of the file to be downloaded.
  • USERNAME is the username on the FTP server.
  • Countersign is the password for the user on the FTP server.

To upload a file to an FTP server, the command would exist:

curl -T FILENAME SERVER_ADDRESS -user USERNAME:Countersign

Again where:

  • SERVER_ADDRESS is the address of the FTP server.
  • FILENAME is the name of the file to be downloaded.
  • USERNAME is the username on the FTP server.
  • PASSWORD is the password for the user on the FTP server.

At some bespeak, the curlicue developers removed SFTP support from the libcurl. If you need to download a file, via SSH, you'll need to use the sftp command.

Why use scroll

Ane of the biggest benefits of curl is that it can exist used without interaction. Because of that, it's perfectly suited for scripting. Y'all'll run into many instances of Linux installer scripts that make use of curl. As an installer script runs, you might well see roll do its matter by downloading necessary dependencies. And then if y'all're writing a Linux bash (or installer) script, scroll volition most certainly be your friend. For more information on curl (and there's a lot of information technology), consequence the control man curlicue and read through the transmission page.

Acquire more about Linux in TechRepublic Academy!

As well see:

  • How to apply the Linux watch control for easier output tracking (TechRepublic)
  • How to use the Linux screen command to keep your remote processes running (TechRepublic)
  • How to gear up an SFTP server on Linux (TechRepublic)
  • How to monitor a Linux log file in real time (TechRepublic)
  • ICANN makes last infinitesimal WHOIS changes to address GDPR requirements (ZDNet)