Code guide

Generate UUIDs in Bash and the Terminal

Generate UUIDs from the command line with uuidgen or /proc, including lowercase output and bulk generation.

You do not need a program to make a UUID at the shell. Most systems ship uuidgen, and Linux exposes a UUID through the kernel random interface.

Key takeaways

  • uuidgen prints a UUID on macOS and most Linux systems.
  • On Linux, cat /proc/sys/kernel/random/uuid also works.
  • macOS uuidgen prints uppercase; pipe through tr for lowercase.

Generate one UUID

uuidgen is the portable option. macOS prints uppercase, so normalize to lowercase when your system expects it. On Linux the kernel interface is a dependency-free alternative.

uuidgen                       # e.g. 4F8B1A9A-... (uppercase on macOS)
uuidgen | tr 'A-F' 'a-f'      # force lowercase

# Linux, no uuidgen needed:
cat /proc/sys/kernel/random/uuid

Generate many at once

A short loop writes a batch to a file for fixtures, seed data or imports.

for i in $(seq 1 100); do uuidgen; done > uuids.txt

FAQ

Generate UUIDs in Bash and the Terminal questions

What UUID version does uuidgen create?

By default uuidgen creates a random version 4 UUID on most systems. Use uuidgen -t for a time-based v1 where supported.

Why is my uuidgen output uppercase?

macOS uuidgen prints uppercase. Pipe it through tr "A-F" "a-f" to get the common lowercase form.

How do I generate UUIDs without uuidgen?

On Linux, read /proc/sys/kernel/random/uuid, which returns a fresh UUID each time.

Generate UUID in Bash - uuidgen and Terminal