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
uuidgen- Generates a random UUIDtr -d '\n'- Removes the newline character at the endpbcopy/xclip- Copies the result to your clipboard
Setting an alias
This can be aliased for easy reuse.
- Edit your shell configuration file (most likely
~/.zshrcif you're using the default macOS terminal, or~/.bashrcif you're using Bash):
nano ~/.zshrc
- 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"
- 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