When working within a graphical user interface (GUI), downloading a file is as simple as clicking a link in your web browser. However, if you are managing a remote Linux server via SSH, or if you simply prefer the speed and efficiency of the terminal, you do not have access to a visual web browser.
Instead, you must rely on powerful command-line network tools. One of the most universally installed and versatile utilities in the Linux ecosystem is cURL (Client for URLs). While it is heavily used by developers to interact with APIs, learning how to download files from the command line using curl is an essential skill for any Linux user.
Verifying Curl is Installed
Before you begin, you should verify that cURL is actually installed on your system. Fortunately, it comes pre-installed on almost every modern Linux distribution, including Ubuntu, Debian, CentOS, and Fedora.
- Open your terminal application.
- Type
curl --versionand press Enter. - If you see a version number (such as
curl 7.81.0), you are ready to proceed. If your terminal returns a “command not found” error, you can easily install it on Ubuntu/Debian by typingsudo apt install curl.
Downloading a File with the Original Filename (-O)
The most common scenario is downloading a file and saving it to your computer with the exact same name it has on the remote server (for example, downloading a file named installer.sh).
To do this, you must use the uppercase -O (capital letter O) flag.
- In your terminal, navigate to the directory where you want to save the file (e.g.,
cd ~/Downloads). - Type
curl -Ofollowed by the full URL of the file. - Example:
curl -O https://example.com/software/installer.sh - Press Enter.
Curl will instantly begin downloading the file, displaying a live progress bar, the total file size, and your current download speed. The file will be saved in your current working directory as installer.sh.
Downloading a File with a Custom Filename (-o)
Sometimes, the file on the server has a confusing, dynamically generated name (such as download?id=12345), or you simply want to rename the file as soon as it hits your hard drive.
To rename a file during the download process, you must use the lowercase -o flag, followed by your desired filename.
- Type
curl -ofollowed by your custom filename, and then the URL. - Example:
curl -o my_custom_script.sh https://example.com/download?id=12345 - Press Enter.
The file will be downloaded and instantly saved to your computer as my_custom_script.sh.
Following Redirects (-L)
When downloading software, the URL you are provided is often just a shortcut that redirects your request to a different server (like a content delivery network or an AWS S3 bucket). By default, cURL will not follow these redirects. It will simply download a tiny, useless HTML file containing the redirect notice.
To force cURL to follow the redirect and download the actual target file, you must add the uppercase -L (Location) flag.
Example: curl -L -O https://github.com/example/project/releases/latest/download.tar.gz
You can combine flags easily. By typing -LO, you instruct cURL to both follow any redirects and save the file using its original remote filename, ensuring a flawless download every time.