liam.pm

Command line UUID generation

Generate a UUID and copy it to your clipboard.

Basic usage

macOS/BSD systems:

uuidgen | tr -d '\n' | pbcopy

Linux systems:

uuidgen | tr -d '\n' | xclip -selection clipboard
# or
uuidgen | tr -d '\n' | xsel --clipboard

Breakdown

  1. uuidgen - Generates a random UUID
  2. tr -d '\n' - Removes the newline character at the end
  3. pbcopy / xclip - Copies the result to your clipboard

Setting an alias

This can be aliased for easy reuse.

  1. Edit your shell configuration file (most likely ~/.zshrc if you're using the default macOS terminal, or ~/.bashrc if you're using Bash):
nano ~/.zshrc
  1. Add the following line to create your alias:

macOS:

alias uuid="uuidgen | tr -d '\n' | pbcopy"

Linux:

alias uuid="uuidgen | tr -d '\n' | xclip -selection clipboard"
  1. Apply the changes by running:
source ~/.zshrc

Now you can simply type uuid in your terminal to generate a UUID and copy it to your clipboard.

Variations

See the UUID

If you want to see the UUID before copying it:

macOS:

uuidgen | tr -d '\n' | tee >(pbcopy)

Linux:

uuidgen | tr -d '\n' | tee >(xclip -selection clipboard)

Lowercase

macOS:

uuidgen | tr '[:upper:]' '[:lower:]' | tr -d '\n' | pbcopy

Linux:

uuidgen | tr '[:upper:]' '[:lower:]' | tr -d '\n' | xclip -selection clipboard