wget is a command-line utility designed for downloading files from the web. It supports HTTP, HTTPS, and FTP protocols, making it a versatile tool for retrieving content directly from the terminal. Unlike graphical download managers, wget operates entirely through the command line, offering advanced features like recursive downloads, bandwidth throttling, and resuming interrupted downloads. For developers, system administrators, and power users, wget is an indispensable tool for automating file retrieval tasks.
While macOS comes with its own set of command-line tools, wget is not included by default. This guide will walk you through the process of installing wget on your Mac and demonstrate how to use it effectively for various tasks.
Installing wget Using Homebrew
Homebrew is a package manager for macOS that simplifies the installation of software and tools not included with the operating system. To install wget, you first need to ensure Homebrew is installed on your Mac. If you haven’t installed Homebrew yet, follow these steps:
- Open the Terminal application. You can find it in Applications > Utilities > Terminal.
- Paste the following command and press Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
. - Follow the on-screen instructions to complete the installation.
Once Homebrew is installed, you can proceed to install wget:
- In the Terminal, type
brew install wget
and press Enter. - Homebrew will download and install wget along with any necessary dependencies.
After the installation is complete, you can verify it by typing wget --version
in the Terminal. This command will display the installed version of wget, confirming that the installation was successful.
Basic Usage of wget
With wget installed, you can start using it to download files from the web. The most basic command involves specifying the URL of the file you want to download. For example:
wget https://example.com/file.zip
This command downloads the file and saves it in your current working directory. If you want to save the file with a different name, use the -O
option followed by the desired filename:
wget -O myfile.zip https://example.com/file.zip
Downloading Entire Websites
One of wget’s most powerful features is its ability to download entire websites for offline viewing. This is particularly useful for archiving web content or creating local backups. To download a website, use the --mirror
option:
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent https://example.com
This command ensures that all necessary files, including images and stylesheets, are downloaded, and the links are adjusted for local viewing.
Limiting Download Speed
If you need to limit the download speed to avoid overwhelming your network, wget provides the --limit-rate
option. For example, to limit the download speed to 500KB/s, use:
wget --limit-rate=500k https://example.com/largefile.zip
This is particularly useful when downloading large files on a shared network.
Resuming Interrupted Downloads
wget allows you to resume interrupted downloads using the -c
option. If your download is interrupted due to a network issue, simply rerun the command with this option:
wget -c https://example.com/largefile.zip
wget will pick up where it left off, saving you time and bandwidth.
Using wget with Authentication
Some websites require authentication to access certain files. wget supports basic HTTP authentication using the --user
and --password
options. For example:
wget --user=username --password=password https://example.com/protectedfile.zip
This allows you to download files from password-protected areas of a website.