brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl --limit-rate keeps a big download from eating your whole connection

Curl
~/tips/tip-curl-limit-rate

curl -L --limit-rate 2M -O https://example.com/images/debian.iso

Caps the speed of a curl download or upload so the rest of the network stays usable.

A large download in a terminal happily takes all the bandwidth it can get. Fine at 3 a.m., less fine when someone in the house is on a video call. curl has a built-in throttle for exactly this, and I think it deserves more use.

The option is --limit-rate <speed>. Without a suffix the number is in bytes per second. You can append k, M, G, T or P, and the curl docs point out these are 1024-based, so 1k is 1024 bytes:

curl -L --limit-rate 2M -O https://example.com/images/debian.iso

That downloads the file at roughly 2 megabytes per second, which is about 17 megabit, and leaves the rest of the line for everyone else. It works for uploads too, so a big -T upload to a WebDAV share or a backup endpoint can be tamed the same way. Since curl 8.19.0 you can also give a fraction such as 2.5M, with a period as the decimal mark whatever your locale says.

Mind the bytes versus bits. Internet plans are sold in megabit, curl counts megabytes, so --limit-rate 10M is around 84 megabit and not 10. I’d do that conversion before picking a number.

The caveat: the limit is an average over several seconds, not a hard ceiling at every moment, so you’ll see short bursts above it. It also applies to each transfer on its own. Two curls with --limit-rate 2M next to each other use about 4M together. If you also set --speed-limit (the option that aborts a transfer that is too slow), the docs say that one takes precedence and can make the rate limiting a bit less precise.

Further reading: curl man page: –limit-rate

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link