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 -r fetches only part of a file, like the last 500 bytes of a log

Curl
~/tips/tip-curl-range-partial-download

curl -r 0-99 https://example.com/big.log

Downloads a chosen byte range, such as only the end of a large file.

To look at the head or tail of a big remote file I do not need to download all of it.

curl -r 0-99 https://example.com/big.log
curl -r -500 https://example.com/big.log

-r sends a Range header. 0-99 returns the first 100 bytes, because both ends are included, and -500 returns the last 500. The server has to support it, which curl -I shows as Accept-Ranges: bytes. A server that ignores the header answers with the whole file and status 200, so look at the status line with -i before trusting the result. A successful range request answers with 206 Partial Content, and several ranges can be combined with a comma.

Further reading: curl manual

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