In the daily operation and maintenance of Linux servers, downloading files, fetching scripts, or synchronizing data from the web is a routine task. While `curl` is available on most modern servers, Wget remains the preferred command-line download tool for many system administrators.
The name "Wget" combines "World Wide Web" and "Get." It supports HTTP, HTTPS, and FTP protocols. Its standout feature is its non-interactive nature—it can continue running in the background even after the user logs out—along with robust capabilities for resuming interrupted downloads and performing recursive downloads. Whether you are writing automated deployment scripts or pulling large dependency packages from overseas sources, Wget is an indispensable tool.
This article begins with the most fundamental download commands and gradually explores Wget’s advanced features and troubleshooting techniques.
I. Basic Operations: Downloading and Saving
The simplest way to use Wget is to provide the URL of the target file:
wget https://example.com/software.tar.gz
Once executed, Wget will download the file to your current directory and display a real-time progress bar in the terminal (showing the amount downloaded, transfer speed, and estimated time remaining).
Customizing the Saved Filename (`-O`)
If the original filename in the URL is a string of meaningless characters (e.g., `download.php?id=123`), you can rename the file:
wget -O custom_name.tar.gz https://example.com/download.php?id=123
*(Note: Use an uppercase "O" for the `-O` flag. In contrast, the lowercase `-o` flag is used to redirect download logs to a specific file instead of displaying them on the screen.)*
Resuming Interrupted Downloads (`-c`)
When downloading large datasets—potentially several gigabytes in size—a network interruption can be frustrating if it forces you to restart the entire process. By using the `-c` flag, Wget checks for an existing file with the same name in the current directory and resumes the download from where it left off:
wget -c https://example.com/large_dataset.zip
This is perhaps Wget’s most essential feature; it is highly recommended to always include this flag when downloading large files.
II. Practical Operations: Rate Limiting, Background Execution, and Automation
1. Limiting Download Speed (`--limit-rate`)
On production servers, downloading files without bandwidth restrictions can crowd out traffic needed for core business operations. Use `--limit-rate` to cap the speed (supports `k` for KB/s and `m` for MB/s):
wget --limit-rate=2m https://example.com/video.mp4
2. Background/Silent Downloads (`-b`)
When downloading very large files—and you don’t want to keep a terminal window open the entire time—use the `-b` flag to move the process to the background:
wget -b https://example.com/huge_file.iso
Wget will create a `wget-log` file in the current directory; you can monitor the download progress at any time using `tail -f wget-log`.
3. Ignoring SSL Certificate Errors (`--no-check-certificate`)
Sometimes, when downloading files from internal test servers that use self-signed certificates, Wget may throw an error and refuse to proceed. If you are certain the source is secure, you can bypass certificate verification:
wget --no-check-certificate https://internal.test.com/patch.zip
4. Configuring Retries and Timeouts (`--tries` / `--timeout`)
In cross-border network environments (e.g., downloading files from a U.S.-based server to a server in China), unstable connections can frequently lead to timeouts. While the default number of retries is 20, you can customize both the timeout duration and the retry count:
wget --tries=3 --timeout=15 https://example.com/file.zip
In this example, a connection is considered timed out if there is no response for 15 seconds, and the process will attempt to retry up to 3 times. III. Advanced Techniques: Request Spoofing and Recursive Mirroring
1. Customizing Request Headers and User-Agent
Many overseas websites block default Wget requests. You can bypass these restrictions by masquerading as a web browser:
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://example.com/protected_file.zip
Alternatively, you can include a specific `Referer` header:
wget --referer=https://google.com https://example.com/file.zip
2. Downloading from Sites Requiring Authentication
For sites using HTTP Basic Authentication, you can provide your username and password directly via command-line arguments:
wget --http-user=admin --http-password=yourpassword https://example.com/secure/
3. Recursive Mirroring of Entire Directories (Use with Caution)
Wget can function like a web crawler, downloading an entire directory from a target site to your local machine (often used for creating offline backups of documentation):
wget -r -np -k -p https://example.com/docs/
`-r`: Recursive download.
`-np`: Do not follow links to parent directories (prevents infinite crawling).
`-k`: Convert absolute links in HTML files to relative links, making them easier to browse offline.
`-p`: Download all resources required to display the page (such as images and CSS).
IV. Best Practices: Writing Robust Automation Scripts
When writing automation scripts (e.g., in Shell or Python), relying solely on a basic `wget` command can be risky. If a file returns a 404 error or the network connection drops, your script might hang. Consider the following practices:
1. Use `-q` (quiet mode) and check the exit status code:
if wget -q https://example.com/file.zip; then
echo "Download successful; proceeding to the next step."
else
echo "Download failed; terminating script."
exit 1
fi
2. Using Proxies: If your server is in an internal network (intranet), you can configure a proxy by setting the `http_proxy` environment variable (e.g., `export http_proxy=...`) or by using the `-e use_proxy=yes` flag within the `wget` command. V. The Ultimate Bottleneck for Download Speeds: Network Infrastructure and I/O
Once you have mastered the various parameters of `wget`, you will realize that the efficiency of downloading large files is often determined not by the tool itself, but by the underlying network and storage performance of the server.
If you use `wget` on a Jtti server to pull large model weights or massive datasets from overseas sources, your download speed will be directly constrained by the quality of the international network egress and the packet loss rate. During evening peak hours, standard international connections are highly susceptible to packet loss, which triggers frequent TCP retransmissions—often causing the `wget` progress bar to stall or the operation to time out entirely.
While `wget` may appear as just a simple command-line instruction, its actual efficiency depends on the network foundation upon which it operates. Features like `-c` (for resuming interrupted downloads) and `-b` (for background, silent execution) make your operational tasks much more manageable; meanwhile, pairing these with Jtti’s high-speed network and NVMe storage ensures that your downloads are always a step ahead. Visit the official Jtti website to explore high-performance cloud server solutions tailored for high-concurrency downloads and data-intensive workloads.
EN
CN