A GUID (Globally Unique Identifier) is a globally unique identifier that can be generated through several different algorithms. The GUIDs on this site are generated using a secure random number generator.
UUIDs are 128-bit values typically represented as 32 hexadecimal digits displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and 4 hyphens). For example: 550e8400-e29b-41d4-a716-446655440000
A Version 1 UUID is a universally unique identifier that is generated using a timestamp and the MAC address of the computer on which it was generated. This version includes:
A Version 4 UUID is a universally unique identifier that is generated using random numbers. The Version 4 UUIDs produced by this site were generated using a secure random number generator. This version includes:
A Version 7 UUID is a universally unique identifier that is generated using a timestamp, a counter and a cryptographically strong random number. Generally, Version 7 UUIDs have better entropy (i.e. randomness) than Version 1 UUIDs. This version includes:
Version 7 UUIDs are particularly useful for database primary keys because they maintain time-ordering while providing good randomness.
A Nil/Empty UUID is a special form that contains all zeros. It has the format: 00000000-0000-0000-0000-000000000000 and is often used to represent a null or undefined UUID.
Version | Generation Method | Time-ordered | Privacy | Use Case |
---|---|---|---|---|
Version 1 | Timestamp + MAC address | Yes | Low | Distributed systems where uniqueness is critical |
Version 4 | Random | No | High | General purpose, privacy-sensitive applications |
Version 7 | Timestamp + Random | Yes | High | Database keys, sortable identifiers |
Bash is a Unix shell and command language, which serves as an enhanced version of the Bourne Shell (sh). As the default shell for most Linux distributions and Unix systems, Bash is renowned for its powerful scripting capabilities and high level of environmental control. Bash scripts can perform a variety of tasks, ranging from simple file operations to complex system administration tasks. Features of Bash include command line argument expansion, piping, redirection, pattern matching, and command substitution, making Bash highly flexible when dealing with files and text.
Bash also supports advanced programming structures such as functions, arithmetic operations, command grouping, loops, and conditional statements, enabling the easy implementation of complex automation tasks. Another important feature of Bash is its extensive support for environment variables and shell script variables, allowing users to customize and optimize their working environment. The extensibility of Bash is also evident in its ability to utilize external commands and programs, as well as interact with other programming languages through shell scripts.
The uuidgen utility represents the most streamlined approach to UUID generation. This built-in tool ensures compliance with UUID standards while maintaining implementation simplicity:
uuidgen
For programmatic use, you can capture the output in a variable:
uuid=$(uuidgen)
echo $uuid
This approach leverages Linux's kernel-level random number generator, offering a robust solution that draws from the system's entropy pool. Access is achieved through a dedicated system file:
Copyuuid=$(cat /proc/sys/kernel/random/uuid)
echo $uuid
The OpenSSL-based approach provides a cryptographically secure method for UUID generation. It generates a random byte sequence and formats it according to UUID specifications:
uuid=$(openssl rand -hex 16 | sed 's/\(..\)/\1-/g; s/.$//')
echo $uuid
This method uses `/dev/urandom` to generate random data, then pipes it to the tr command to filter characters, retaining only hexadecimal characters (a-f0-9), followed by fold to wrap the output into 32-character wide lines, and finally head to take the first line as the UUID.
uuid=$(cat /dev/urandom | tr -dc 'a-f0-9' | fold -w 32 | head -n 1)
echo $uuid
This method uses the od command to convert random data into hexadecimal representation and then formats it into UUID format with the awk command.
od -An -N 16 -tx1 /dev/urandom | awk '{printf "%s%s%s%s-%s-%s-%s-%s%s%s\n", substr($1,3,4), substr($1,2,4), substr($1,1,4), substr($2,3,4), substr($2,2,4), substr($3,1,2), substr($2,1,2), substr($3,2,2), substr($3,3,2)}'
This method combines base64 encoding with dd command to generate random data, then filters out hexadecimal characters with tr and formats it into a UUID.
uuid=$(cat /dev/urandom | base64 | head -c 16 | tr -dc 'a-f0-9' | fold -w 2 | head -n 5 | tr -d '\n' | sed 's/\(.\)\(.\)/\1-\2/g;s/-/4-/g;s/-.\{3\}$//')
echo $uuid