17 Curl Command Examples in Linux
Table of Contents
- Install Curl
- Basic Syntax
- Curl Command Examples
- 1. Basic usage:
- 2. Send a POST request
- 3. Download a file using the curl command
- 4. Resume uncompleted downloads
- 5. How to follow the redirect
- 6. Limit maximum transfer rate
- 7. How to download multiple files using Curl Command
- 8. Check your external IP address.
- 9. Send cookies using Curl command
- 10. How to check HTTP headers
- 11. How to Set HTTP Authentication
- 12. Download or Upload files from or to FTP server
- 13. Set Firefox as a User Agent for Curl
- 14. Using proxies with Curl Command
- 15. Download a file, if updated before the specific time
- 16. Download a file, if updated after a specific time
- 17. Check if the website is Down
Curl Command in Linux
Curl utility in Linux is used to transfer files to or from a server using protocols like HTTP, HTTPS, FTP, SCP, SFTP, etc. This command is easy to use and can work without user interaction. Curl command can also be used to download or upload files with supported options like proxy support, resume the transfer, etc. Alternatively to transfer files we can use wget command.
Most of the Linux systems today come with curl command preinstalled. So to check whether it is installed on your system already or not type
curl in the command line. If you get output like
curl: try 'curl --help' or 'curl --manual' for more information this the curl is installed on your system otherwise install it using below command.
Install Curl on Ubuntu or Debian
curl on Ubuntu or on Debian based systems run below command:
sudo apt install curl
Install Curl on Fedora or CentOS
curl on Fedora or on CentOS run below command:
sudo yum install curl
Following is the basic syntax:
curl [options] [URL...]
options: Options used with the curl command
URL: The targeted URL
Curl Command Examples
1. Basic usage:
When we use this command without any options it will return source code for the given URL.
For example, run below command to retrieve source code for
You will get the source code of the www.example.com page located here.
2. Send a POST request
To send a POST request using curl command
--data option is used. You can send parameters with it like given below:
curl --data "name=Mona&age=20" https://www.example.com/update_info
3. Download a file using the curl command
To download a file using curl command
-O (uppercase) or
-o (lowercase) option is used. While
-O (uppercase) option saves the file with the original name and
-o (lowercase) option saves a file with the given name.
Following command uses
-O (uppercase) option to download file with the original name which will save the file with the name
curl -O http://www.example.com/example_file.zip
Now run below command which downloads
example_file.zip and saves it with name
curl -O new_file.zip http://wwww.example.com/example_file.zip
4. Resume uncompleted downloads
To resume uncompleted download by using the curl command
-C - option is used with the option
For example, download Ubuntu ISO file using below command and then stop it:
curl -O http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
Now you can resume above uncompleted download using below command:
curl -C - -O http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
5. How to follow the redirect
Sometimes the non-WWW version is redirected to WWW version of the website. If you visit
yahoo.com using curl command you will be notified that
redirected means the page is redirected to
The output should be:
At such time you should use the
-L option which follows the given URL until it reaches to destination URL.
curl -L yahoo.com
6. Limit maximum transfer rate
--limit-rate option you can limit the maximum transfer rate like given below:
curl --limit-rate 300K -O http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
7. How to download multiple files using Curl Command
You can use curl like below to download multiple files:
curl -O http://ubuntu.biz.net.id/16.04.0/ubuntu-16.04.0-desktop-amd64.iso -O http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
Above command will download Ubuntu 16.04 ISO file and Ubuntu 18.04 ISO file.
8. Check your external IP address.
You can also check your IP address by using curl command. Run below command to check the IP address and other IP address related info:
or to check any IP address info type:
Alternatively, you can also use the
curl ifconfig.mecommand. It query only IP address.
You can send cookies with curl using the
-b option. In the following example, we are downloading Ubuntu ISO file with curl and sending cookie “name:john123” with it.
curl -b "name=john123" -O http://ubuntu.biz.net.id/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
10. How to check HTTP headers
Headers are used to send additional information about itself so to check such headers you can use following curl command:
curl -I http://www.yahoo.com
11. How to Set HTTP Authentication
Whenever you need authentication for accessing the page by using username and password you can do such things using
-u option in Curl.
In following command username and password is set for authentication for accessing
curl -u username:password ftp://www.mywebsite.com/my_file.zip
12. Download or Upload files from or to FTP server
You can download files from FTP server using the curl command
-u option along with the
-O option is used like given below:
curl -u username:password -O ftp://example_server/example_file.tar.gz
You can upload files from FTP server using the curl command
-u option along with the
-T option is used like given below:
curl -u username:password -T ftp://example_server/example_file.tar.gz
For authentication, you can pass username and password.
13. Set Firefox as a User Agent for Curl
When you blocked from accessing or downloading content when you use a Curl agent. Then to customize the user agent name you can use
In the below example curl will act as Firefox user-agent:
curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" https://example.com/
14. Using proxies with Curl Command
You can also use proxies like HTTP, HTTPS, and SOCKS. In curl command to transfer data through a proxy, server
-x option is used.
In the following example, we will use 192.168.143.106:8080 as a proxy to download
curl -x 192.168.143.106:8080 -O http://www.example.com/example_file.zip
You can also authenticate with the username and password like given below, remember here we have used
-U (uppercase) option for authentication:
curl -U username:password -x 192.168.143.106:8080 -O http://www.example.com/example_file.zip
15. Download a file, if updated
before the specific time
To download a file which updated before a specific time then you can do by using
-z option in the curl command. With the
-z option you have to specify the date.
In the following example, the command downloads the file if the file updated before 28 Feb 2019.
curl -z -28-Feb-19 http://www.mywebsite.com/xyz.zip
16. Download a file, if updated
after a specific time
To download the file which updated after a specific time then you can do by using -z option.
In the following example, the command downloads the file if the file updated after 28 Feb 2019.
curl -z 28-Feb-19 http://www.mywebsite.com/xyz.zip
17. Check if the website is Down
Sometimes we are not able to access a website at such time to check whether the website is down, you can use
To check whether
www.facebook.com is available or run below command:
curl -Is https://www.facebook.com -L | grep HTTP/
For the above command, if you get output like
HTTP/2 200 then the website is available otherwise if you get output like
HTTP/2 503 Service Unavailable then the specified website is down.
You have successfully learned 15 Curl command examples in Linux. If you have any queries please don’t forget to comment below.
How to install Skype on Debian 9
How to Install Eclipse IDE on Debian 10
How to Install WordPress with LAMP Stack on Debian 9
How to Install Opera Browser on Linux Mint 19
Bash Case Statement with Examples
How to Install RubyMine on Debian 9
How to Install RubyMine on Ubuntu 18.04
How to Install PyCharm on Linux Mint 19
How to Install Google Chrome on Debian 10
How to Install Adobe Flash Player on Debian
How to Remove Docker Images, Networks, Containers and Volumes
How to Install Apache Tomcat 9 on Debian 9