We’ll show you 5 basic cURL command examples, and explain them in detail. cURL is a very useful command line tool used to transfer data from or to a server. cURL supports various protocols, such as FILE, HTTP, HTTPS, IMAP, IMAPS, LDAP, DICT, LDAPS, TELNET, FTP, FTPS, GOPHER, RTMP, RTSP, SCP, SFTP, POP3, POP3S, SMB, SMBS, SMTP, SMTPS, and TFTP. If you’d like to find out more about cURL itself, check out our article: What is cURL?
What is cURL, and what does it do?
cURL is a tool to transfer data from or to a server, using one of the many supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). This tool is designed to work without user interaction, making it excellent for automation. It offers proxy support, user authentication, FTP uploading, HTTP posting, SSL connections, cookies, file transfer resume, Metalink, and many other features listed below. cURL can be used in many different and interesting ways. With this tool you can download, upload and manage files, check your email address, or even update your status on some social media websites, and even check the weather outside. In this article will cover five of the most useful and basic uses of the cURL tool on any Linux VPS. For detailed explanation of what is cURL, please visit our dedicated blog post on What is cURL?
1. Check URL with cURL command
One of the most common and simplest uses of cURL is typing the command itself, followed by the URL you want to check:
This command will display the content of the URL on your terminal.
2. Save the output of the URL to a file with cURL command
The output of a cURL command can be easily saved to a file by adding the -o option to the command, as shown below:
curl -o website https://domain.com/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 41793 0 41793 0 0 275k 0 --:--:-- --:--:-- --:--:-- 2.9M
In this example, the output will be saved to a file named ‘website’ in the current working directory. You can save in other directories using the same method as other programs by using forward-slashes.
3. Download files with cURL command
You can download files with cURL by adding the -O option to the command. It is used for saving files on the local server with the same names as on the remote server:
curl -O https://domain.com/file.zip
In this example, the ‘file.zip’ zip archive will be downloaded to the current working directory.
You can also download the file with a different name by adding the -o option to cURL:
curl -o archive.zip https://domain.com/file.zip
This way the ‘file.zip’ archive will be downloaded and saved as ‘archive.zip’.
cURL can also be used to download multiple files simultaneously, as shown in the example below:
curl -O https://domain.com/file.zip -O https://domain.com/file2.zip
cURL can be also used to download files securely via SSH using the following command:
curl -u user sftp://server.domain.com/path/to/file
Note that you have to use the full path of the file you want to download.
4. Get HTTP header information from a website with a cURL command
You can easily get HTTP header information from any website you want by adding the -I option (capital ‘i’) to cURL.
curl -I http://domain.com 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
5. Access an FTP server with a cURL command
To access your FTP server with cURL, use the following command:
curl ftp://ftp.domain.com --user username:password
cURL will connect to the FTP server and list all files and directories in the user’s home directory.
You can download files via FTP, too:
curl ftp://ftp.domain.com/filename.extension --user username:password
and upload a file onto the FTP server:
curl -T filename.extension ftp://ftp.domain.com/ --user username:password
You can also check the cURL manual page to see all available cURL options and functions:
This covers most of the basic tools and features that most new users of cURL would seek to use. Of course, the capabilities of cURL are far greater than this guide, with most features intended for experienced users.
See Also – Find Large Files in Linux
Of course, if you use one of our Linux VPS Hosting services, you can always contact and ask our expert Linux admins (via chat or ticket) about cURL commands and anything related to cURL. They are available 24×7 and will provide information or assistance immediately and they can show you cURL command examples for your needs.
PS. If you liked this post about cURL command examples, please share it with your friends on the social networks using the buttons below or simply leave a reply. Thanks.