Bash & Linux · uuidgen · Command Reference

Generate a UUID in Bash & Linux

Complete reference for generating UUIDs from the command line — covers uuidgen, the kernel random UUID device, and macOS/Windows equivalents.

Quick Start

Generate a Random UUID (v4) with uuidgen

Most Linux distributions ship uuidgen pre-installed (part of util-linux). It is the fastest way to get a UUID from the terminal:

Bash
$ uuidgen 550e8400-e29b-41d4-a716-446655440000
Bash — lowercase (default is often uppercase)
$ uuidgen | tr ‘[:upper:]’ ‘[:lower:]’ 550e8400-e29b-41d4-a716-446655440000
💡

uuidgen defaults to v4 (random)

Plain uuidgen with no flags generates a random UUID v4 on most systems. Use uuidgen -t for time-based v1, or uuidgen -r to force random v4 explicitly.

Without uuidgen

Generate a UUID Without Installing Anything

If uuidgen isn’t installed, the Linux kernel exposes a random UUID directly through the proc filesystem:

Bash (Linux only)
$ cat /proc/sys/kernel/random/uuid 550e8400-e29b-41d4-a716-446655440000
Bash — using OpenSSL (works on macOS too)
$ openssl rand -hex 16 | sed ‘s/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*/\1\2\3\4-\5\6-\7\8-/’ # Note: openssl rand does not set version/variant bits — not RFC-strict
⚠️

openssl rand output is not a real UUID

The openssl rand approach produces random hex data formatted to look like a UUID, but it does not set the required version (4) and variant (8/9/a/b) bits. For a spec-compliant UUID, use uuidgen or /proc/sys/kernel/random/uuid instead.

Platform Differences

uuidgen on Linux vs macOS

PlatformCommandNotes
Linux (most distros)uuidgenPart of util-linux, usually pre-installed. Install via apt install uuid-runtime if missing.
macOSuuidgenPre-installed on all macOS versions. Outputs uppercase by default.
Windows (PowerShell)[guid]::NewGuid()Not a Bash command, but the PowerShell equivalent for Windows users.
WSL / Git BashuuidgenAvailable if util-linux is installed in the WSL distro.
Bash — install uuidgen on Debian/Ubuntu if missing
$ sudo apt install uuid-runtime

Scripting

Using uuidgen in Shell Scripts

Assign a generated UUID to a variable, or generate many at once for bulk file naming or test data:

Bash — store in a variable
#!/bin/bash MY_UUID=$(uuidgen) echo “Generated: $MY_UUID” touch “/tmp/$MY_UUID.log”
Bash — generate 10 UUIDs in a loop
for i in $(seq 1 10); do uuidgen done > uuids.txt # Or a one-liner: for i in {1..10}; do uuidgen; done
Bash — validate UUID format with regex
is_valid_uuid() { [[ “$1” =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ ]] } if is_valid_uuid “550e8400-e29b-41d4-a716-446655440000”; then echo “Valid” fi

FAQ

Bash UUID FAQ

Run uuidgen in your terminal. It is part of the util-linux package and is pre-installed on most Linux distributions. If it is missing, install it with sudo apt install uuid-runtime on Debian/Ubuntu systems. It generates a random UUID v4 by default.
Yes. On Linux, run cat /proc/sys/kernel/random/uuid to read a fresh random UUID directly from the kernel, no package installation required. This works on any Linux system with a standard kernel, including minimal containers.
Mostly yes. uuidgen is pre-installed on macOS and produces the same RFC-compliant UUID v4 format. One difference: macOS uuidgen outputs uppercase letters by default, while Linux typically outputs lowercase. Pipe through tr ‘[:upper:]’ ‘[:lower:]’ to normalize the case if needed.
You can generate random hex data formatted like a UUID using openssl rand -hex 16, but the result will not have the correct version and variant bits set, so it is not a spec-compliant RFC 4122/9562 UUID. For a properly formatted UUID from the command line, use uuidgen or read directly from /proc/sys/kernel/random/uuid on Linux.

Need to Generate a UUID Right Now?

Skip the terminal — use our free browser-based generator for all 8 UUID versions.

Open UUID Generator