Generating lowercase UUIDs with uuidgen on macOS

Josh Sherman
1 min read
Command-line Interface Apple

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 willed 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:

uuidgen | tr A-Z a-z

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:

uuidgen | tr A-F a-f

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'
fi

The reason I aliased it back over uuidgen instead of opting for the shorter 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:]"'
Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles