Using Curl on Ubuntu 18.04 | 16.04 with Examples

This brief tutorial shows students and new users how to install and use the curl command on Ubuntu 18.04 | 16.04.

There are many tools and software available in Ubuntu to download and upload files from and to remote servers. Curl is one of those tools, and works with one of these supported protocols: FTP, HTTP, IMAP, LDAP, POP3, SCP, SFTP, SMB, SMBS, SMTP, TELNET and TFTP to transfer data to and from remote servers.

If you’re a student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use..

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices.

When you’re ready to learn how to use Curl to download files, follow the steps below:

Step 1: Installing Curl on Ubuntu

Curl packages are included in Ubuntu default repositories and installing is very simple.

To install, simply run the commands below.

sudo apt install curl

After installing, you can check to see if it’s installed and ready by typing the commands below and press enter.

curl

It should output similar line as shown below:

Output:
curl: try 'curl --help' or 'curl --manual' for more information

That’s all to it!

Curl is now ready to be used on Ubuntu.

Step 2: Using Curl

As we mentioned above, Curl comes with many options. To see all available options to use the Curl, type this command: curl --help

In its simplest form, you can use Curl to print out a source code or a website by running the commands below:

curl https://example.com

One of the many usages of Curl is to download files. When you use Curl with the -o or --output option, you can download a file and write it into a name you specify.

The -o, –output <file> Write to file instead of stdout

Example:

curl -o linux.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.3.18.tar.gz

When you use  Curl with an uppercase O option, you can download and save the file, preserving its original name.

The -O, –remote-name Write output to a file named as the remote file

Example:

curl -O https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.3.18.tar.gz

If you want to lookup a website header, you can use Curl with an -I option.

Example:

curl -I https://www.bbc.com/

That command above will print out the BBC website header;

HTTP/2 200 
server: Apache
nel: {"report_to":"default","max_age":2592000,"include_subdomains":true,"failure_fraction":0.01}
x-cache-action: HIT
cache-control: max-age=60
x-cache-age: 34
content-type: text/html
report-to: {"group":"default","max_age":2592000,"endpoints":[{"url":"https://europe-west1-bbc-otg-traf-mgr-bq-prod-4591.cloudfunctions.net/report-endpoint","priority":1}],"include_subdomains":true}
expires: Fri, 21 Feb 2020 22:35:33 GMT
content-language: en
etag: "de4ad647a27f51ce00628a8709ce5e58"
x-pal-host: pal1121.back.live.telhc.local:80
accept-ranges: bytes
date: Fri, 21 Feb 2020 22:49:34 GMT
via: 1.1 varnish
age: 142
x-lb-nocache: true
x-fastly-cache-status: HIT-STALE-CLUSTER
x-served-by: cache-pwk4942-PWK
x-cache: HIT
x-cache-hits: 2, 1
x-timer: S1582325374.219647,VS0,VE4
vary: Accept-Encoding
content-length: 260751

Curl provides many more functions. If you want to see all the options, run the command below:

curl --help

These are just some of the functions available:

Usage: curl [options...] 
     --abstract-unix-socket  Connect via abstract Unix domain socket
     --anyauth       Pick any authentication method
 -a, --append        Append to target file when uploading
     --basic         Use HTTP Basic Authentication
     --cacert  CA certificate to verify peer against
     --capath

That’s it!

Conclusion:

This post showed you how to install and use Curl on Ubuntu 18.04 | 16.04. If you find any error above, please use the comment form below to report it.

Thanks!

You may also like the post below:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.