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 no-clobber keeps the old file and gives the new download a number

Curl
~/tips/tip-curl-no-clobber-numbered

curl --no-clobber -O https://example.com/report.pdf

Keep the file you already have and let the new download land under a numbered name.

By default curl -O overwrites a file with the same name without asking. --no-clobber keeps the old one and saves the new download next to it.

Run the same download twice and look at the folder:

curl --no-clobber -O https://example.com/report.pdf
curl --no-clobber -O https://example.com/report.pdf
ls report.pdf*

With curl 8.22 and older you end up with report.pdf and report.pdf.1, then report.pdf.2. Those copies do not open with a double click, because the number sits after the extension. The man page says curl 8.23 changes this for names with an extension: the number goes before it, so you get report-1.pdf. Check curl -V before a script depends on either pattern.

I like it for things that change at the same URL, like an exported report or a nightly build, when I want to compare the new one with the old one before I throw anything away.

This is a different tool from --skip-existing, which does not download at all when the file exists. With no-clobber the transfer always happens, so you pay for the bandwidth every time. It also only protects files curl writes itself with -o or -O; a shell redirect like > report.pdf still overwrites. The option needs curl 7.83 or newer.

Further reading: curl man page

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