Skip to content

Instantly share code, notes, and snippets.

@MurphysChaos
Created December 11, 2018 17:40
Show Gist options
  • Save MurphysChaos/918215434044f0473b3f5ca82a0b599f to your computer and use it in GitHub Desktop.
Save MurphysChaos/918215434044f0473b3f5ca82a0b599f to your computer and use it in GitHub Desktop.
Generate a random GUID/UUID
#!/usr/bin/env bash
# 1. Get 16 characters (128 bits) from a pseudorandom number generator
# 2. Convert characters to hexadecimal representation
# 3. Remove spaces from string
# 4. Insert dashes
echo $(head -c 16 /dev/urandom | od -t x8 -An | sed 's/ //g' | sed -E 's/(.{8})(.{4})(.{4})(.{4})(.{12})/\1-\2-\3-\4-\5/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment