Bash

Generate UUID

admin by @admin ADMIN
5d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Several portable ways to mint a v4 UUID from the shell — useful for request IDs, idempotency keys, temporary filenames.
Bash
Raw
# Linux — kernel-provided
cat /proc/sys/kernel/random/uuid
# f47ac10b-58cc-4372-a567-0e02b2c3d479

# Cross-platform — uuidgen (BSD-style on macOS, util-linux on Linux)
uuidgen
uuidgen | tr '[:upper:]' '[:lower:]'        # macOS uppercases — fix it

# Via python (always available)
python3 -c "import uuid; print(uuid.uuid4())"

# Via openssl (somewhat random — not a true v4 but good enough as a token)
openssl rand -hex 16

# Or build something shorter and URL-safe for non-UUID use
openssl rand -base64 16 | tr -d '=+/' | head -c 16
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.