How to Download Files Using the curl Command in Linux

If you need to download a zip archive, a bash script, or a raw dataset directly onto your Linux server, you cannot rely on a graphical web browser like Chrome or Firefox. You must grab the file directly from the terminal. While many tutorials recommend the wget tool, it is not always installed by default on minimal server distributions. The ultimate, universally available alternative is the curl command.

While curl (Client URL) is primarily designed to transfer raw data and test API endpoints, it functions beautifully as a file downloader if you know which flags to use.

The Problem with Basic Curl

If you simply type curl followed by a web address, you will experience a chaotic mess. For example:

curl https://example.com/script.sh

Instead of saving the file to your hard drive, Linux will instantly dump the entire raw contents of that script directly onto your terminal screen in a massive wall of text. curl defaults to standard output (your screen).

How to Actually Download the File

To tell curl to write the data to a physical file on your hard drive, you must use the output flag.

Method 1: Keep the Original Filename (Uppercase -O)

If you are downloading a file named installer.zip and want it to keep that exact name on your server, use the uppercase letter O (as in Output):

curl -O https://example.com/installer.zip

Press Enter. curl will download the file and save it in your current working directory as installer.zip.

Method 2: Give the File a New Name (Lowercase -o)

Sometimes you are downloading a file with a messy URL like download?id=12345. To force curl to save the file under a clean, custom name, use the lowercase letter o followed by your desired filename:

curl -o latest_backup.zip https://example.com/download?id=12345

Press Enter. curl will grab the data from the URL but save it neatly to your hard drive as latest_backup.zip, complete with a live progress bar showing you the download speed and estimated time remaining.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.