Do You Have 5 Minutes?
John Scott
jscott at posteo.net
Tue Feb 3 22:15:44 EST 2026
Bernie Hoefer wrote:
> I'm going to spend my 5 minutes on /usr/bin/base64.
Pedantic side note: the base64 utility is from GNU, but unlike many similar commands, it has never been part of any international standard (the Portable Operating System Interface [POSIX, IEEE 1003.1-2024], the Single UNIX Specification [SUS, a superset and profile of POSIX], or the Linux Standard Base standard). It can't be expected to be available on Unix-like systems in general, but there's an alternative.
uuencode supports the '-m' option to convert data to a base 64 representation. This was added to POSIX in 2001 and, like GNU's base64, it's required to use the same base 64 alphabet that is conventionally used on the internet such as in MIME: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/uuencode.html#tag_20_142_10_01
If you really want just the base 64 data and don't want the uuencode header and trailer lines, they can be stripped out using ridiculousness like this:
$ printf "%s" $'All aboard! \xf0\x9f\x9a\x86\n' | uuencode -m /dev/stdout | tail -n +2 | grep -vxF -e '===='
QWxsIGFib2FyZCEg8J+ahgo=
A very good use for base 64 data is that it lets you take an entire file's contents—of any format whatsoever, even a binary one—and encode it into a data URI; at https://http.dev/data-url#example one can see how this works. A very fun use case for this is the following: programs and apps for scanning QR codes usually expect the QR code's contents to be a URI. Using a data URI with base 64 data, you can encode arbitrary files or binary data *inside the QR code itself*, instead of linking to somewhere on the internet. (If your file is too big to fit in a single QR code, the "structured append" feature can be used to split the data up.)
In particular I was able to record a few seconds of a sound effect, compress it as well as I could, and put the entire audio file into a QR code and mail it on a postcard—even dumb smartphone apps will try to open the data: URI in a browser, and the browser will allow the file to be opened with a native app. It's very silly but I have some use cases that are just as silly 😉
If you just want to make a data URI there are tools just for this like 'dataurl', available in Debian and derivatives, which are more practical than fumbling with shell pipelines except when portability is an outstanding concern.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 411 bytes
Desc: This is a digitally signed message part
URL: <http://lists.cinlug.org/pipermail/cinlug/attachments/20260204/81c9b5dd/attachment.sig>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6270 bytes
Desc: not available
URL: <http://lists.cinlug.org/pipermail/cinlug/attachments/20260204/81c9b5dd/attachment.p7s>
More information about the cinlug
mailing list