The roll command is quite useful and flexible. The intent of the tool is to transfer data, without user interaction, to or from a server, using i of the many supported protocols. Information technology is that list of protocols that helps curl manage to be so flexible, as the command 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 healthy list of possibilities. It also means curl can transfer just about any blazon of data. Gyre can even display the source lawmaking of a URL. All of this without requiring user interaction (a crucial feature for scripting).

I want to show you how to make use of this command (one you lot'll frequently observe in Linux howtos and scripts). I'll be demonstrating on Uncomplicated Bone, just the command works on nearly every available Linux distribution. Whorl is also available on macOS and Windows.

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

Installing coil

Your Linux distribution should have ringlet installed past default. If not, the installation is quite uncomplicated. On a Debian derivative, the installation command would exist:

sudo apt install roll

Yous can cheque the installation by issuing the control curl –version. You should see the version number of the installed application (on my Elementary OS auto, it'due south 7.47.0).

Using curl

Permit's showtime see how curl can be used at its simplest. Say you want to view the source of a spider web site. We'll utilise the curl site equally an example. Consequence the command:

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

Yous can now curlicue through the HTML for that site (Effigy A).

Figure A

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

Of course, that example is quite limited. Let's use scroll to pull down a file from a site. Permit'south stick with the aforementioned example. Say you want to download the HTML for the roll site to view subsequently. For this, we'll apply the -o switch like then:

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

The higher up command would download the HTML code from the curl site and salvage it as whorl.html. Of class, coil isn't only capable of downloading source HTML. Say you have a file y'all desire to download from a site. Whorl can handle this like so:

scroll http://SERVER_ADDRESS/FILENAME -o FILENAME

Where SERVER_ADDRESS is the URL of the server and FILENAME is the name of the file to be downloaded. Say for example, yous desire to download the latest release of Ubuntu Server. That can be done like so:

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

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

curl -u USERNAME:Countersign http://SERVER_ADDRESS -o FILENAME

Where:

  • USERNAME is the username on the server.
  • Countersign 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 likewise use curl with an FTP server. Say you need to download a file from an FTP server that happens to be password protected. The command for this would exist:

curl ftp://SERVER_ADDRESS/FILENAME -user USERNAME:PASSWORD -o FILENAME

Where:

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

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

roll -T FILENAME SERVER_ADDRESS -user USERNAME:Password

Again where:

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

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

Why use curl

One of the biggest benefits of curl is that information technology tin can be used without interaction. Because of that, it'south perfectly suited for scripting. You'll run into many instances of Linux installer scripts that make utilize of curl. As an installer script runs, you might well encounter scroll do its thing by downloading necessary dependencies. And so if you lot're writing a Linux bash (or installer) script, curl volition most certainly exist your friend. For more information on gyre (and there'south a lot of it), issue the command man curl and read through the manual folio.

Larn more nigh Linux in TechRepublic Academy!

Too run into:

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