How to use Curl on Ubuntu Linux with examples

|

|

This tutorial guides new users and students on installing and using the curl command on Ubuntu 18.04 and 16.04. Curl, a tool to download and upload files from/to remote servers, supports numerous protocols including FTP and HTTP. The article also explains how to use Curl for various tasks such as printing a website source code…

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

Many tools and software are 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 distribution.

Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.

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 see if it’s installed and ready by typing the commands below and pressing enter.

curl

It should output a 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.

Use 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 specified name.

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

You can use Curl with an- I option to look up a website header.

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

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, please report it in the comment form below.


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



Leave a Reply

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

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading