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: a curl config file can download a list of URLs, each under its own name

Curl
~/tips/tip-curl-config-url-list

url = "https://example.com/data/latest.json"

Put url and output pairs in one file and fetch them all with one command.

When a batch of downloads needs custom file names, a loop in the shell is the usual answer. A curl config file with url and output lines does the same without any loop.

Write the pairs in a plain text file, one option per line:

url = "https://example.com/data/latest.json"
output = "stats.json"
url = "https://example.com/files/list.txt"
output = "blocklist.txt"

Then hand the file to curl with -K:

curl -fsS -K downloads.txt

Each output belongs to the url before it, the same way -o pairs with a URL on the command line. Options you put on the command line, like -fsS here, apply to every transfer. You can also add lines such as create-dirs or remote-time to the file itself.

I like that the list is data instead of code. It is easy to read, easy to generate from another script, and easy to keep in git.

One thing to watch: curl runs the transfers one by one and the exit code reflects the last transfer, so an early failure can hide behind a successful last download. Add --fail-early if one bad URL should stop the whole batch. Lines starting with # are comments.

Further reading: curl man page, everything curl: config file

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

Link