When working in a headless Linux server environment, you do not have the luxury of opening a graphical web browser to click a download button. Whether you are retrieving a software package, fetching an installation script, or backing up a remote directory, you must rely entirely on the command line.
For these tasks, mastering the wget command is an essential system administration skill that drastically speeds up your workflow.
What is Wget?
wget (short for World Wide Web get) is a free, non-interactive network downloader utility. It supports HTTP, HTTPS, and FTP protocols.
Because it is non-interactive, it is perfectly suited for automation and scripting. Once you execute a wget command, it does not require any further user input, meaning it can run quietly in the background or within scheduled cron jobs.
How to Install Wget in Ubuntu Linux
While wget comes pre-installed on almost all modern Linux distributions, you can easily install or update it using your package manager if it is missing.
- Open your terminal.
- Run the following command to update your package lists and install the utility:
sudo apt update && sudo apt install wget -y
How to Perform a Basic Download
To download a single file and save it directly to your current working directory, simply type wget followed by the URL.
wget https://example.com/software-package.zip
The terminal will instantly display a progress bar, your current download speed, and an estimated time of completion. The file will be saved using the original filename found in the URL.
Essential Wget Commands and Flags
The true power of wget lies in its extensive list of options and flags. Here are the most useful commands you will use on a daily basis:
1. Rename a File Upon Download (-O)
Often, download URLs generate files with long, confusing alphanumeric names. You can use the -O (capital O, for Output) flag to specify exactly what the file should be named on your local machine.
wget -O easy-name.zip https://example.com/a1b2c3d4e5.zip
2. Resume a Broken Download (-c)
If your internet connection drops while downloading a massive multi-gigabyte ISO file, you do not have to start from scratch. Use the -c (continue) flag to resume the download from exactly where it was interrupted.
wget -c https://example.com/massive-file.iso
3. Download Files in the Background (-b)
If a download is going to take several hours, you do not want it to tie up your terminal session. By using the -b (background) flag, wget will silently perform the task behind the scenes.
wget -b https://example.com/massive-file.iso
To check the progress of a background download, you can view the automatically generated log file by typing: tail -f wget-log.
4. Download Multiple Files from a List (-i)
If you have a batch of files to download, you can place all the URLs into a simple text file (e.g., urls.txt), with one URL on each line. Then, instruct wget to read the file using the -i (input) flag.
wget -i urls.txt
By incorporating wget and its various flags into your Linux toolkit, you can efficiently manage file transfers and automate complex download tasks directly from the terminal.