3 C
Texas
angeloma
Senior Writer and partner

How to use CURL command on Linux?

On our site, there are many tutorials that have helped you learn about Linux, but in them, there is a very particular command called CURL. For example, in the post where I taught you how to install Rust, I used it, but I didn’t explain what it is. Therefore, in this post, I will teach you how to use the CURL command on Linux.

CURL is a command line tool and library for transferring data with URLs. Many download scripts or file transfers use CURL as a means to achieve this. In addition, CURL supports FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP and many other protocols quite popular on networks.

On the other hand, the use of CURL is not limited exclusively to computers but to other devices that use UNIX such as cell phones, cars and is the transfer backend of many of the most popular applications in the world.

Using CURL command on Linux

The idea of this post is to show the use of CURL, not to do it in a theoretical way. The main idea is to do it through examples that demonstrate its use.

- Advertisement -

So, let’s start.

1. Install CURL

Obviously, the first step is to install CURL. It is really simple as it is available in the official repositories of most Linux distributions. So, its installation is limited to a single command.

For Debian, Ubuntu, Linux Mint and derivates

:~$ sudo apt install curl

1.- Install CURL
1.- Install CURL

If you use Fedora:

:~$ sudo dnf install curl

For CentOS and RHEL:

:~$ yum install curl

2. Check the CURL version

The second thing you should do is, check the CURL version. Important to know what news you have available. While it is not essential to have CURL updated to its latest version, it is also not crazy to do so.

:~$ curl --version

2.- Checking the CURL version
2.- Checking the CURL version

3. Display the content of an HTML

A simple way to display the source code of an HTML site from the terminal is with CURL.

:~$ curl http://website.com/page.html

Of course, it is necessary that you place the complete website of your preference.

3.- Showing a HTML page on the terminal thanks to CURL command
3.- Showing an HTML page on the terminal thanks to CURL command

4. Download a file with CURL

This is one of the most common uses we give to CURL. Downloading a file is a really simple task.

:~$ curl -O https://pixabay.com/en/photos/download/ocean-3605547_1280.jpg

4.- Downloading a file
4.- Downloading a file

You can use the -o option to specify the name of the downloaded file.

:~$ curl -o image.jpg https://pixabay.com/en/photos/download/ocean-3605547_1280.jpg

5.- Downloading a file using the -o option
5.- Downloading a file using the -o option

I remind you again that, I’m using test URLs, you have to enter yours.

5. Use a proxy

With CURL it is possible to make connections through a proxy. The proxy may or may not require authentication.

:~$ curl -x your-proxy:8080 -U user_password -O http://domain.com/file

6.- Using a proxy server
6.- Using a proxy server

In case the proxy server does not need authentication, you can omit the option -U.

6. Get HTTP header information from a website

There are occasions when it is necessary to know the information stored in the HTTP headers of some website. It is really easy to do it with CURL.

:~$ curl -I http://website.com

7.- Showing HTTP website header
7.- Showing HTTP website header

7. Limit download rate

If you are connected using mobile data or simply want to limit the CURL download rate, you can do it easily.

:~$ curl --limit-rate 100K -O http://domain.com/file.file

8.- Using a proxy server
8.- Using a proxy server

8. Download file from an FTP server

As I said at the beginning of this post, CURL supports many protocols, not only HTTP but also FTP. Now I will show you how to do it.

:~$ curl -u username:password -O ftp://ftpserver/file.zip

9.- Downloading a file from a FTP server
9.- Downloading a file from an FTP server

In case you do not need authentication, omit the option -u.

9. Upload Files to an FTP server

You can also upload files to an FTP server. The syntax is similar only this time, you should add the -T option.

:~$ curl -u username:password -T myfilepath.jpg ftp://ftpserver/file.zip

Note: I’m using false addresses and that’s why CURL can’t find them. But don’t worry that the commands are correct.

10. Check the CURL help

Of course, the use of the CURL command is very extensive and I only demonstrated some of its uses. For more information about the CURL command, it is convenient to consult its help from the terminal.

:~$ curl --help

10.- CURL help
10.- CURL help

And that’s it.

Conclusion

I hope this article has made clear to you the potential of CURL. There is so much potential that there is still so much to show, but I think the objective has been achieved.

CURL is widely used in script automation of content downloads and is not only used in computer equipment but in many others.

So, if you liked the article share it through your social networks.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article