In Linux, curl is a powerful command-line tool used to transfer data from or to a server using a wide variety of protocols, including HTTP, HTTPS, and FTP. It is often used for testing APIs, downloading files, and automating web-related tasks.
$ curl [options...] <url>The command will print the source code of the example.com homepage in the terminal window.
curl has over 200 options! Here are some of the most common and useful ones.
| Option | Long Version | Description |
|---|---|---|
-O |
--remote-name |
Downloads the file and saves it with the same name as the remote file. |
-o <file> |
--output <file> |
Saves the downloaded output to a specific filename. |
-L |
--location |
Follows redirects if the server reports that the requested page has moved. |
-X <METHOD> |
--request <METHOD> |
Specifies the HTTP request method to use (e.g., POST, PUT, DELETE). |
-H <header> |
--header <header> |
Allows you to add a custom HTTP header to your request. |
This is the simplest use of curl. It will fetch the content from the URL and print its HTML source code directly to your terminal.
$ curl example.comThe -O flag is used to download a file. curl will save it in your current directory using the same name as the remote file.
$ curl -O https://github.com/bobbyiliev/101-linux-commands/archive/refs/tags/v1.0.zipUsing the -o flag, you can specify a new name for the downloaded file.
$ curl -o linux-commands.zip https://github.com/bobbyiliev/101-linux-commands/archive/refs/tags/v1.0.zipThe curl command comes with most of the Linux distributions. But, if the system does not carry the curl by default. You need to install it manually. To install the curl, execute the following commands:
Update the system by executing the following commands:
$ sudo apt update
$ sudo apt upgradeNow, install the curl utility by executing the below command:
$ sudo apt install curlVerify the installation by executing the below command:
$ curl -versionThe above command will display the installed version of the curl command.