What Is the wget Command and How Do You Use It?
The wget command is a powerful, non-interactive
command-line utility used for downloading files from the internet.
Supporting protocols such as HTTP, HTTPS, and FTP, it is a staple tool
for developers, system administrators, and tech enthusiasts alike.
Because it is non-interactive, wget can operate effectively
in the background, allowing users to start a download and disconnect
from the system, or automate complex downloading tasks through scripts.
This overview covers the core functionality of wget, its
key features, and basic syntax to get you started.
Key Features of wget
Unlike standard web browsers or other download tools,
wget is designed for robustness and efficiency over
unstable network connections.
- Background Operation: You can initiate a download and let it run in the background while you perform other tasks or log out of your session.
- Resuming Downloads: If a download is interrupted by
a network failure,
wgetcan resume the download from where it left off, saving time and bandwidth. - Recursive Downloading: It can mirror entire websites by following links and recreating the original directory structure on your local machine.
- Wildcard Matching: Users can specify patterns to download specific file types, such as grabbing all PDFs or images from a directory.
Basic Syntax and Common Examples
The basic structure of a wget command is
straightforward, requiring only the utility name followed by any desired
options and the target URL.
wget [options] [URL]Downloading a Single File
To download a file and save it to your current working directory, simply provide the direct URL:
wget https://example.com/file.zipSaving a File with a Different Name
By default, wget saves the file using its original name
from the URL. You can override this using the -O
option:
wget -O custom_name.zip https://example.com/file.zipResuming an Interrupted Download
If a large download cuts out halfway through, you can append the
-c option to resume the progress:
wget -c https://example.com/large-dataset.tar.gzMirroring an Entire Website
To download a local copy of a website for offline viewing, the
-m (mirror) option enables recursive downloading, page
requisites, and appropriate link conversion:
wget -m https://example.comConclusion and Further Resources
The wget tool is an essential utility for anyone working
within a terminal environment, offering a blend of simplicity for quick
downloads and advanced features for complex web scraping and archiving
tasks.
For more advanced tutorials, specific use cases, and technical guides relating to this command line tool, you can explore further documentation and articles at https://salivity.github.io/wget.