uuid Command Examples in Linux

UUID, short for Universally Unique Identifier, is a standardized format for representing 128-bit identifiers. A UUID is typically represented as a string of 32 hexadecimal digits, separated by hyphens into five groups of varying lengths.

UUIDs are used in a variety of contexts where a unique identifier is needed, such as in distributed computing systems, network protocols, and database systems. They are designed to be globally unique, meaning that the chances of two UUIDs being the same are very low, even when generated by different systems at different times.

The uuid command is a Unix utility that can be used to generate, manipulate, and decode UUIDs. It can generate UUIDs in a variety of formats, including the standard UUID format and several alternative formats. The uuid command can also be used to decode UUIDs, allowing users to extract information about the UUID, such as its timestamp or the version of the UUID specification used.

One common use case for the uuid command is in scripting or programming, where UUIDs may be needed for tasks such as generating unique identifiers for database records or creating temporary files. The uuidgen command, which is often installed alongside the uuid command, can be used to quickly generate a new UUID from the command line.

uuid Command Examples

1. Generate a UUIDv1 (based on time and system’s hardware address, if present):

# uuid

2. Generate a UUIDv4 (based on random data):

# uuid -v 4

3. Generate multiple UUIDv4 identifiers at once:

# uuid -v 4 -n number_of_uuids

4. Generate a UUIDv4 and specify the output format:

# uuid -v 4 -F BIN|STR|SIV

5. Generate a UUIDv4 and write the output to a file:

# uuid -v 4 -o path/to/file

6. Generate a UUIDv5 (based on the supplied object name) with a specified namespace prefix:

# uuid -v 5 ns:DNS|URL|OID|X500 object_name

7. Decode a given UUID:

# uuid -d uuid

Summary

Overall, the uuid command is a useful tool for working with UUIDs on Unix and Unix-like systems. Its ability to generate, manipulate, and decode UUIDs makes it a valuable resource for developers and system administrators who work with distributed systems and other contexts where unique identifiers are needed.

Related Post