Generating lowercase UUIDs with uuidgen on macOS by Josh Sherman


The implementation of uuidgen on Linux returns all lowercase letters by default. The implementation of uuidgen on macOS returns all uppercase letters by default. This triggers the hell out of me, by default.

Usually when I approach consistency between macOS and Linux, both of which I use daily, I will bend Linux to Apple’s will, since that tends to be the path of least resistance.

In this scenario though, I don’t want to have uppercase UUIDs at all, so I’ve wanted Apple more in the direction of Linux.

Armed with my trusty tr command, to translate characters, I was able to pipe the output of uuidgen to it and swap the LETTERS for letters. Said command looks like this:

Works like a champ, but let’s not stop there. Universally unique identifiers (UUIDs) only contain the first six letters of the alphabet, A through F, so we can improve things a bit:

With that bit of golfing out of the way, we can take this command and alias like this:

alias uuidgen='uuidgen | tr A-F a-f'

Better still, only alias it when we’re on a macOS machine:

if [[ `uname` == Darwin ]]; then
	alias uuidgen='uuidgen | tr A-F a-f'

The reason I aliased it back over uuidgen instead of opting for the shorter one
uuid is because I don’t like aliasing commands just to make them shorter, with the exception of git commands.

Just my personal preference, so feel free to name the alias as you see fit!

Just for grins, here’s the more verbose, but same result, that GitHub Copilot suggested to me:

alias uuidgen='uuidgen | tr "[:upper:]" "[:lower:]"'

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.



Please enter your comment!
Please enter your name here