Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash uuidgen Usage: Generate unique identifiers
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
      1. Generate a simple UUID
      2. Generate a random UUID
      3. Generate a time-based UUID
      4. Generate multiple UUIDs
    5. Tips

[Linux] Bash uuidgen Usage: Generate unique identifiers

Overview

The uuidgen command is used to create universally unique identifiers (UUIDs). UUIDs are 128-bit numbers that are used to uniquely identify information in computer systems, making them essential for various applications such as database keys, session identifiers, and more.

Usage

The basic syntax of the uuidgen command is as follows:

uuidgen [options] [arguments]

Common Options

  • -r, --random: Generate a random UUID.
  • -t, --time: Generate a time-based UUID.
  • -h, --help: Display help information about the command.
  • -v, --version: Show the version of the uuidgen command.

Common Examples

Here are some practical examples of how to use the uuidgen command:

Generate a simple UUID

uuidgen

This command will output a randomly generated UUID.

Generate a random UUID

uuidgen -r

This command specifically generates a random UUID.

Generate a time-based UUID

uuidgen -t

This command generates a UUID based on the current time.

Generate multiple UUIDs

uuidgen | xargs -n 1 echo

This command generates a single UUID and can be modified to generate multiple UUIDs by using a loop or by calling uuidgen multiple times.

Tips

  • Use the -r option when you need a UUID that is not based on time, which can be useful for ensuring uniqueness across distributed systems.
  • Consider using UUIDs as primary keys in databases to avoid collisions, especially in distributed environments.
  • Always check the version of uuidgen you are using with the -v option to ensure compatibility with your applications.