How to Set a Quota Limit in Wget?
This article provides a quick overview and practical guide on how to
restrict the total amount of data downloaded during a wget
session. By using the built-in quota flag, you can prevent large
download jobs from consuming all your disk space or exceeding network
bandwidth caps. You will learn the exact syntax for setting these
limits, how wget behaves when a quota is reached, and the
structural limitations of this feature when downloading single versus
multiple files.
The Wget Quota Syntax
To enforce a maximum download size limit in wget, you
use the --quota option (or its short-form equivalent
-Q). This tells the utility to keep track of the cumulative
bytes downloaded during the session and stop fetching new resources once
the specified threshold is crossed.
The basic syntax for the command is:
wget --quota=NUMBER URL
The NUMBER value can be postfixed with specific letters
to denote the unit of measurement:
- g or G for Gigabytes
- m or M for Megabytes
- k or K for Kilobytes
For example, to limit a download session to 500 Megabytes, you would run:
wget --quota=500m http://example.com/downloads/
Critical Behavior and Limitations
Understanding how wget handles the quota limit is
essential to avoid unexpected disk usage, as the feature behaves
differently depending on how many files you are downloading.
- The Single File Exception: The quota check is
not dynamic within a single file download. If you point
wgetto a single 10 GB file but set a quota of50m,wgetwill download the entire 10 GB file. The quota is only checked before a new file begins downloading. - Recursive and Multiple File Downloads: The quota
limit works perfectly when downloading multiple files, such as when
using recursive downloading (
-r) or passing a list of URLs. Ifwgetfinishes downloading a file and notices that the total downloaded bytes have exceeded the quota, it will gracefully abort the session and will not attempt to retrieve the next file in the queue.