Blog
Wild & Free Tools

Generate UUID in Bash, Mac Terminal, Linux, and Windows Command Line

Last updated: January 2026 5 min read
Quick Answer

Table of Contents

  1. macOS Terminal — uuidgen
  2. Linux — uuidgen and /proc
  3. Windows — PowerShell and CMD
  4. UUID in Shell Scripts and CI Pipelines
  5. Frequently Asked Questions

Every major operating system can generate a UUID from the terminal with a single command — no code, no package manager. uuidgen works on macOS and most Linux distros. PowerShell handles Windows. Here is every command with copy-paste examples for Bash scripting, CI pipelines, and one-off generation.

macOS Terminal — uuidgen

# Generate one UUID
uuidgen
# Output: 550E8400-E29B-41D4-A716-446655440000

# Note: macOS uuidgen outputs UPPERCASE by default
# Convert to lowercase:
uuidgen | tr '[:upper:]' '[:lower:]'
# Output: 550e8400-e29b-41d4-a716-446655440000

# Remove dashes:
uuidgen | tr -d '-'
# Output: 550E8400E29B41D4A716446655440000

# Generate 10 UUIDs
for i in {1..10}; do uuidgen; done

# Store in a variable
MY_ID=$(uuidgen | tr '[:upper:]' '[:lower:]')
echo "Generated: $MY_ID"

uuidgen is installed by default on macOS (via the util-linux-adjacent BSD tools). It generates UUID v4 on most modern macOS versions.

Linux — uuidgen and /proc Methods

# Method 1: uuidgen (most distros)
# Install if missing: apt install uuid-runtime (Debian/Ubuntu)
#                    yum install util-linux (RHEL/CentOS)
uuidgen
# Output: 550e8400-e29b-41d4-a716-446655440000

# uuidgen on Linux defaults to lowercase (unlike macOS)

# Method 2: /proc virtual file (any Linux kernel 2.6+)
cat /proc/sys/kernel/random/uuid
# Generates a new UUID each time you read it

# Method 3: Python one-liner (if Python is installed)
python3 -c "import uuid; print(uuid.uuid4())"

# Method 4: Using /dev/urandom directly in Bash
od -x /dev/urandom | head -1 | awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
# Less clean but works anywhere without tools

# Bash script: generate UUID and use in filename
UUID=$(uuidgen)
OUTFILE="export-${UUID}.json"
echo "Saving to $OUTFILE"
Sell Custom Apparel — We Handle Printing & Free Shipping

Windows — PowerShell and Command Prompt

# PowerShell — single UUID
[guid]::NewGuid().ToString()
# Output: 550e8400-e29b-41d4-a716-446655440000

# Uppercase
[guid]::NewGuid().ToString().ToUpper()

# Without dashes
[guid]::NewGuid().ToString('N')
# Output: 550e8400e29b41d4a716446655440000

# Store in variable
$id = [guid]::NewGuid().ToString()
Write-Host "ID: $id"

# Multiple UUIDs
1..10 | ForEach-Object { [guid]::NewGuid().ToString() }

# From CMD (calls PowerShell):
powershell -command "[guid]::NewGuid().ToString()"

# In batch scripts:
for /f "usebackq" %%g in (
  `powershell -command "[guid]::NewGuid().ToString()"`
) do set UUID=%%g
echo %UUID%

UUID in Shell Scripts and CI Pipelines

#!/bin/bash
# Common patterns for UUIDs in shell scripts

# 1. Unique temp directory
TMPDIR="/tmp/job-$(uuidgen)"
mkdir -p "$TMPDIR"
trap "rm -rf $TMPDIR" EXIT

# 2. Unique log file per run
LOG_ID=$(uuidgen | tr '[:upper:]' '[:lower:]')
LOGFILE="logs/run-${LOG_ID}.log"
echo "Logging to $LOGFILE"

# 3. Idempotency key for API requests
IDEMPOTENCY_KEY=$(uuidgen)
curl -X POST https://api.example.com/orders   -H "Idempotency-Key: $IDEMPOTENCY_KEY"   -H "Content-Type: application/json"   -d '{"item": "widget"}'

# 4. GitHub Actions — generate UUID in workflow step
# - name: Generate unique build ID
#   id: build-id
#   run: echo "id=$(uuidgen | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT

For generating UUIDs interactively without opening a terminal, the WildandFree UUID Generator works in any browser — useful during development when you need a quick test ID.

Generate a UUID Without Opening a Terminal

Need a UUID now and no terminal handy? Generate UUID v4 in your browser instantly — click copy, done. No signup, no download, works on any device.

Open Free UUID Generator

Frequently Asked Questions

Does uuidgen generate UUID v4?

On Linux with util-linux 2.31+, uuidgen generates v4 (random) by default. Earlier versions generated v1 (time-based). Use uuidgen -r to explicitly request random (v4) or uuidgen -t for time-based (v1). On macOS, uuidgen always generates a random UUID.

How do I generate UUID on a system without uuidgen?

On Linux: cat /proc/sys/kernel/random/uuid reads a new UUID from the kernel each time. If Python is installed: python3 -c "import uuid; print(uuid.uuid4())". On any system with OpenSSL: openssl rand -hex 16 | sed "s/\(........\)\(....\)\(....\)\(....\)\(............\)/\1-\2-\3-\4-\5/"

How do I generate a UUID in a GitHub Actions workflow?

Use the uuidgen command in a run step: echo "id=$(uuidgen | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT. GitHub Actions runners (ubuntu-latest) include uuidgen by default. Access the value in subsequent steps as steps..outputs.id.

Is the UUID generated by uuidgen cryptographically secure?

Yes. uuidgen on Linux reads from /dev/urandom. The PowerShell [guid]::NewGuid() uses the .NET Guid.NewGuid() which reads from the OS cryptographic random number generator. Both are safe for session tokens and non-guessable IDs.

David Rosenberg
David Rosenberg Technical Writer

David spent ten years as a software developer before shifting to technical writing covering developer productivity tools.

More articles by David →
Launch Your Own Clothing Brand — No Inventory, No Risk