How to Download Files from the Linux Terminal Using the wget Command

When working on a headless Linux server without a graphical desktop interface, you cannot simply open a web browser to download a software package or an installation script. Instead, you must rely on terminal-based tools to interact with the web. The most ubiquitous and reliable tool for this job is the wget command.

What is the wget Command?

wget (short for World Wide Web get) is a non-interactive network downloader. It is designed to download files from the internet using HTTP, HTTPS, and FTP protocols. Because it is non-interactive, it can work in the background, making it ideal for automated bash scripts and server administration tasks.

How to Perform a Basic Download

The syntax for a standard download is extremely simple. You type wget followed by the direct URL of the file you want to download.

wget https://example.com/software-package.tar.gz

When you press Enter, wget will resolve the URL, connect to the server, and begin the download. It displays a progress bar, the download speed, and the estimated time remaining directly in the terminal. The file will be saved in your current working directory using its original filename.

How to Save a File with a Different Name

Sometimes URLs are messy and do not reflect the actual file contents (e.g., https://example.com/download?id=12345). If you run a basic wget command on that URL, the file will be saved locally as “download?id=12345”.

To force wget to save the file with a specific name, use the -O (capital O for Output) flag.

wget -O installer.zip https://example.com/download?id=12345

This command will download the file and save it locally as installer.zip.

How to Resume a Broken Download

If you are downloading a massive 5GB ISO file and your SSH connection drops or the server temporarily loses internet connectivity, the download will fail. Rather than starting from scratch and wasting bandwidth, you can tell wget to resume the download from where it left off by using the -c (continue) flag.

wget -c https://example.com/large-linux-distro.iso

wget will inspect the partially downloaded file in your directory, communicate with the web server, and request only the remaining bytes.

How to Download Files in the Background

If you are downloading a large file and you need to continue using the terminal for other tasks, you can push wget to the background using the -b (background) flag.

wget -b https://example.com/massive-database-dump.sql

The command will immediately return you to the terminal prompt. wget will continue downloading the file silently and will write the download progress logs to a file named wget-log in your current directory. You can monitor the progress at any time by running tail -f wget-log.

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.