When you are working on a remote Linux server via a terminal, you do not have access to a web browser like Google Chrome to click and download files. If you need to pull a software installation package, a dataset, or a configuration file directly from the internet onto your server, you must use the wget command.
The wget (World Wide Web Get) command is a non-interactive network downloader. It is incredibly robust, capable of downloading massive files in the background, surviving network interruptions, and even mirroring entire websites. In this guide, you will learn how to wield this essential Linux utility.
Step 1: The Basic Download
The simplest way to use wget is to provide it with a direct URL to a file.
wget https://example.com/software-package.tar.gz
When you run this command, wget instantly connects to the server and begins downloading the file into your current working directory. You will see a progress bar on your screen detailing the download speed, the percentage completed, and the estimated time remaining.
Step 2: Downloading in the Background
If you are downloading a massive 50GB dataset, you do not want to stare at the progress bar for three hours. Worse, if your SSH connection drops, the download will fail. You can force wget to run silently in the background using the -b (background) flag.
wget -b https://example.com/massive-dataset.zip
The command will instantly return control of the terminal to you. It will silently write the download progress into a file named wget-log in the same directory. You can check the progress at any time by reading that log file:
tail -f wget-log
Step 3: Resuming an Interrupted Download
If you were downloading a large file without the background flag and your internet connection suddenly dropped, you do not have to start over from zero. wget has a built-in resume function triggered by the -c (continue) flag.
wget -c https://example.com/software-package.tar.gz
wget will look at the partially downloaded file on your hard drive, calculate exactly how many bytes are missing, and request the server to start the download from that exact point.
Step 4: Changing the Filename
Sometimes, URLs end in long, unreadable strings of characters (e.g., download?id=12345). If you download this, the resulting file will be named “download?id=12345”, which is highly annoying. You can force wget to rename the file immediately upon downloading using the -O (capital O for Output) flag.
wget -O clean-name.zip https://example.com/download?id=12345
By mastering the wget command, you guarantee that you can efficiently pull any necessary data from the internet directly into your server environment without ever relying on a graphical browser.