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 can write the download URL into the file itself

Curl
~/tips/tip-curl-xattr-origin-url

curl --xattr -O https://example.com/tools/file.tar.gz

Store where a file came from in its extended attributes, so you can look it up later.

A folder full of downloads tells you nothing about where each file came from. With --xattr, curl writes the URL into the file’s extended attributes while it saves it.

Add the flag to any download that writes to a file:

curl --xattr -O https://example.com/tools/file.tar.gz

curl stores the URL in an attribute called xdg.origin.url and, for HTTP, the content type in mime_type. On Linux you read them back with getfattr, on macOS with xattr:

getfattr -d file.tar.gz
xattr -l file.tar.gz

On a Mac the output looks like user.xdg.origin.url: https://example.com/tools/file.tar.gz. I find that handy for the odd tarball or PDF where I want to check months later which version page it came from, without keeping a separate notes file.

Extended attributes are fragile, though. Copying the file to a FAT or exFAT stick, zipping it, or sending it through a tool that does not preserve them drops the URL without a word. The file system also has to support them in the first place; if it does not, curl prints a warning and saves the file anyway. So treat the attribute as a handy hint, not as your only record.

Further reading: curl man page, getfattr 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