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.
For implementation context, continue with Bulk UUIDs, UUID v4, and Go. These pages cover the closest generator, comparison, validation or storage decisions without repeating this guide.
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/uuidGenerate 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.txtGenerate a batch with failure handling
Use a Bash arithmetic loop to avoid depending on seq. Check that uuidgen is installed, stop if generation fails, and normalize each result when your import requires lowercase text. Run the script with bash rather than sh.
On Linux util-linux, uuidgen --random explicitly requests v4. Options differ across platforms; consult the local manual before using Linux-specific flags on macOS. Keep an import uniqueness constraint even for generated fixtures.
#!/usr/bin/env bash
set -euo pipefail
command -v uuidgen >/dev/null || { echo "uuidgen is required" >&2; exit 1; }
for ((i = 0; i < 100; i++)); do
uuidgen | tr 'A-F' 'a-f'
done > uuids.txt