Fun With Curl

Posted on by David Singer | Updated:
Reading Time: 4 minutes

cURL is a Linux command that is used to transfer multiple data types to and from a server. It operates utilizing the libcurl library, which allows it to use the following protocols to move information:

  • Telnet
  • HTTP
  • FTP
  • IMAP
  • POP3
  • SCP
  • SFTP
  • SMTP
  • TFTP
  • LDAP
  • Files

Check The Status of A Site

To check if a website is available, we often use the following commands to get the apache response code which indicates if the site is up, down, or in a condition that needs to be addressed:

curl -Is | head -n 1
HTTP/1.1 200 OK
curl -I
HTTP/1.1 200 OK
Date: Sun, 16 Oct 2016 23:37:15 GMT
Server: Apache/2.4.23 (Unix)
X-Powered-By: PHP/5.6.24
Connection: close
Content-Type: text/html; charset=UTF-8

or, to get the status code itself, pipe the curl command to head -n 1|cut -d$’ ‘ -f2

curl -I | head -n 1|cut -d$' ' -f2

To follow a redirect use:

curl -L

Downloading With cURL

If you need to download a file to the current folder you are in and want to keep the same filename, run:

root@server:~/test$ curl -O
root@server:~/$ curl -O
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5120k  100 5120k    0     0  2450k      0  0:00:02  0:00:02 --:--:-- 2450k

or, if you need to choose a different location or filename, use

curl -o website.html
root@server:~/$ curl -o
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5120k  100 5120k    0     0  2311k      0  0:00:02  0:00:02 --:--:-- 2311k

In the above command, we downloaded a small file originally named and saved it as cURL can also be used to download multiple files simultaneously, as shown in the examples below:

curl -O [URL1] -O [URL2] -O [URL3] 
curl -O -O

Download A File Over SSH

Another popular method for using cURL is to download files securely via SSH using the following command:

curl -u root s

FTP Using cURL

To access an FTP server with cURL, use the following command:

curl --user username:password

You can also download files using cURL over FTP:

curl --user username:password

Additionally, we can upload a file onto the FTP server via cURL:

curl -T file.txt --user username:password
Be aware when passing information via plaintext as these are only usage examples.

Resume A Broken Download Using cURL

If you are downloading a file and lose your internet connection for some reason, cURL can resume the download where it left off:

curl -O -C -

Use cURL To Get Your IP Address

curl -s

Verify If A Website Supports HTTP/2 With Curl

curl -I --http2 -s | grep HTTP
HTTP/2 200

Use cURL To Expand Shortlinks

If an untrusted short link is sent to you, verify its destination using the following command:

curl -sIL | grep ^Location;

Transfer Large Files Using cURL And

The website is a simple file sharing service for the command line that allows you to transfer files up to 10G, and stores the file for up to 10 days. They also allow for the encryption of a file if needed. We’re going to use it to upload and download an encrypted file:

# Encrypt files with password using gpg
$ cat /test/test.txt|gpg -ac -o-|curl -X PUT --upload-file "-"

#enter a passphrase twice and will then provide a link to download the encrypted file.

# To download and decrypt
$ curl|gpg -o- > /test/test.txt

Check EMail Using cURL

You can connect to Gmail via the command line to check unread mail using cURL

curl -u username:password --silent "" | grep -oPm1 "(?<=)[^<]+" | sed '1d'

curl -u username --silent "" | perl -ne 'print "\t" if //; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'

cURL The Weather!!!


or the moon phase!


cURL For A Random Number

curl ""

Use cURL To Grab A Cheatsheet


Need A QR Code? cURL


cURLing And Social Media

Grab the latest YouTube video title and URL by username, the newest Tweet from Liquidweb, or check your favorite Twitch channel.

curl -s
curl -s
curl -s

Also, you can tweet using cURL:

curl -u user:pass -d status="Tweeting from the shell"

Convert A Document Using cURL

curl \ \
  -F from=html \
  -F to=pdf \
  -F input_files[]=@<(echo hello)

Define A Word Using cURL

cURL can connect to and define a word for you. Just add the word you need to identify after the “d:” like so;
(we also pipe the command through ‘less’ so we have a better view of the output)

curl |less
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   550    0   550    0     0   3179      0 --:--:-- --:--:-- --:--:--  3160
220 dictd 1.12.1/rf on Linux 4.4.0-1-amd64 <auth.mime> <>
250 ok
150 1 definitions retrieved
151 "website" wn "WordNet (r) 3.0 (2006)"
    n 1: a computer connected to the internet that maintains a
         series of web pages on the World Wide Web; "the Israeli web
         site was damaged by hostile hackers" [syn: {website},
         {website}, {internet site}, {site}]
250 ok [d/m/c = 1/0/28; 0.000r 0.000u 0.000s]
221 bye [d/m/c = 0/0/0; 0.000r 0.000u 0.000s]

check this one out yourself:

curl |less

Final Thoughts

Just like many other Linux commands, cURL has multiple benefits and uses. It is a versatile and functional part of a more extensive toolkit you have available to meet various needs. Can you think of a few situations where cURL can be useful to you?

Learn More Today!

Have thoughts, questions, or concerns about this or any other topic?
We have Support and Solution Teams standing by around the clock who have an in-depth knowledge of these and other web hosting technologies, especially those discussed in this article. Give us a call today at 1.800.580.4985, or open a chat or ticket with us to explore how you can take advantage of these or other opportunities we have available.
We look forward to hearing from you!

Avatar for David Singer

About the Author: David Singer

I am a g33k, Linux blogger, developer, student, and former Tech Writer for My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Latest Articles

Controlling PHP settings with a custom php.ini file

Read Article

How to install Puppet Server on Linux (AlmaLinux)

Read Article

Email security best practices for using SPF, DKIM, and DMARC

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article