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 one of the many supported protocols. It is that list of protocols that helps curl manage to be so flexible, equally 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. Information technology besides ways roll tin can transfer just about whatsoever type of data. Gyre 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 yous how to make employ of this command (one you'll ofttimes find in Linux howtos and scripts). I'll be demonstrating on Elementary Os, but the command works on nearly every available Linux distribution. Curl is also available on macOS and Windows.

SEE: 20 quick tips to make Linux networking easier (costless PDF) (TechRepublic)

Installing ringlet

Your Linux distribution should accept whorl installed by default. If not, the installation is quite simple. On a Debian derivative, the installation command would be:

sudo apt install curl

Y'all tin can check the installation by issuing the command roll –version. You should run into the version number of the installed application (on my Unproblematic Os machine, it'south seven.47.0).

Using curl

Let'southward kickoff see how curl can exist used at its simplest. Say you want to view the source of a spider web site. Nosotros'll utilize the curl site every bit an case. Consequence the command:

roll https://scroll.haxx.se | less

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

Figure A

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

Of form, that example is quite limited. Let'due south use gyre to pull downwardly a file from a site. Let's stick with the same instance. Say you want to download the HTML for the gyre site to view afterwards. For this, we'll use the -o switch similar so:

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

The above control would download the HTML lawmaking from the scroll site and salve it every bit curl.html. Of course, curlicue isn't merely capable of downloading source HTML. Say y'all have a file you desire to download from a site. Curlicue can handle this like and so:

roll 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, yous want to download the latest release of Ubuntu Server. That tin can be washed similar and then:

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

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

curl -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 as well employ curl with an FTP server. Say you need to download a file from an FTP server that happens to be password protected. The control for this would be:

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

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 password for the user on the FTP server.

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

curl -T FILENAME SERVER_ADDRESS -user USERNAME:Countersign

Again where:

  • SERVER_ADDRESS is the accost 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 countersign for the user on the FTP server.

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

Why use curl

1 of the biggest benefits of curl is that it can be used without interaction. Because of that, it'southward perfectly suited for scripting. You lot'll run into many instances of Linux installer scripts that make use of curl. As an installer script runs, you might well see curl do its matter past downloading necessary dependencies. So if yous're writing a Linux bash (or installer) script, curl will most certainly be your friend. For more than data on curl (and there's a lot of information technology), consequence the command human being gyre and read through the manual page.

Learn more about Linux in TechRepublic Academy!

Too run into:

  • How to utilise the Linux sentry command for easier output tracking (TechRepublic)
  • How to use the Linux screen control to go along your remote processes running (TechRepublic)
  • How to prepare an SFTP server on Linux (TechRepublic)
  • How to monitor a Linux log file in real fourth dimension (TechRepublic)
  • ICANN makes last minute WHOIS changes to accost GDPR requirements (ZDNet)