When operating a Linux server via SSH, you do not have access to a web browser like Chrome or Firefox to download files. If you need to download a software installation script, a compressed archive, or grab the HTML of a webpage for debugging, you must pull that data directly from the internet using the command line. The two standard utilities for this task are wget and curl.
While both tools download data from the internet, they are designed for slightly different workflows. wget is excellent for downloading large files directly to your hard drive, while curl is designed to output data directly to the terminal screen (or pipe it to other programs). In this guide, you will learn the essential syntax for both commands.
Using wget (Web Get)
If your goal is simply to download a file from a URL and save it to your server, wget is usually the easiest tool for the job.
Basic Download
To download a file and save it in your current directory with its original name, simply type wget followed by the URL.
wget https://example.com/software-package.tar.gz
As the file downloads, wget provides a clear progress bar, download speed, and estimated time of completion.
Saving with a Different Name
Often, download links are messy or generated by scripts (e.g., download.php?id=123). To force wget to save the file with a clean name, use the -O (capital O for Output) flag.
wget -O clean-package.tar.gz https://example.com/download.php?id=123
Resuming Broken Downloads
If you are downloading a massive 5GB ISO file and your SSH connection drops at 90%, you do not need to start over. Use the -c (continue) flag to resume the download exactly where it stopped.
wget -c https://example.com/large-linux-distro.iso
Using curl (Client URL)
While curl can also download files, its superpower is interacting with APIs, sending data, and outputting text directly to the console.
Viewing Raw Data (No Download)
If you just want to see the HTML code of a webpage or the raw text of a script without saving a file to your hard drive, use curl.
curl https://example.com
The raw HTML will instantly flood your terminal screen. You can use this to quickly verify if a web server is responding properly.
Downloading a File
If you want curl to act like wget and save the file instead of displaying it on the screen, you must use the -O (capital O) flag. This tells curl to save the file using the name provided in the URL.
curl -O https://example.com/software-package.tar.gz
If you want to specify a custom name, use the lowercase -o flag.
curl -o clean-package.tar.gz https://example.com/download.php?id=123
Following Redirects
Many modern URLs do not point directly to a file; they point to a redirect service that bounces you to the final file location. curl will not follow these redirects by default, resulting in a downloaded file that contains a 301 Redirect HTML error instead of your software.
To force curl to follow the link to its final destination, use the -L (Location) flag.
curl -L -O https://example.com/latest-release-link
By mastering both wget and curl, you guarantee that you can always retrieve software, scripts, and data from the internet directly into your headless Linux environment.