The Power of cURL: From Basic Commands to Advanced Usage
The cURL command-line tool is one of the most useful and versatile programs available. Its comprehensive HTTP implementation means that if there’s a URL for it, cURL can handle it. From fetching web pages and downloading files to installing software and checking IP addresses, cURL offers a wide range of functionalities that are essential for developers and power users.
8. Fetch a Web Page
In its simplest form, cURL fetches a URL and displays its contents directly in your terminal:
curl info.cern.ch
Depending on the content type of the URL, you’ll see different outputs. For a web page, you’ll view its HTML source:
To save a web page, you can redirect the output to a file:
curl info.cern.ch > info.cern.ch.html
Notice how cURL sends timing information to stderr when the output is redirected:
URLs containing special characters like ? or # must be carefully handled. Surround URLs with single quotes to avoid issues:
curl 'info.cern.ch'
7. Download a File
When downloading binary files such as images or documents, the default behavior of cURL can be problematic:
curl -o neo-the-cat.jpg https://placecats.com/neo/300/200
This saves the file locally. You can also use the -# or –progress-bar option for a progress bar:
curl --progress-bar -o neo-the-cat.jpg https://placecats.com/neo/300/200
6. Install Software
Sometimes, software installation instructions use cURL. For example, the popular command-line history utility, Atuin, can be installed with a single line:
curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh
This command downloads and runs a shell script hosted online. The curl options ensure secure and reliable execution. Always be cautious when running scripts downloaded from the internet.
Running a shell script downloaded from the internet can be risky. Ensure you trust the source and verify security measures like HTTPS to protect against Man-in-the-Middle attacks. Consider downloading and examining the file before execution.
5. Check Your IP Address
