Linux Commands

How to Generate Universally Unique Identifiers (UUIDs) with Uuidgen

Universally Unique Identifiers, or UUIDs, are a standardized way of generating and identifying resources in a globally unique manner. These identifiers are commonly used in computer systems where they can identify records from server databases or network interfaces.

In Linux, you can use the “uuidgen” tool to generate UUIDs. In this article, we will go over how to use the “uuidgen” tool to generate UUIDs.

What is a UUID

A UUID is a 128-bit value that is generated in a way that it is unique across all systems in the world. This means that you can use a UUID to identify resources without having to worry about conflicts with other systems. The UUID is typically represented as a string of 32 hexadecimal characters, separated into groups of 8, 4, 4, 4, and 12 characters.

Generating a UUID

Update the system’s list of available packages using the apt update command:

$ sudo apt update

Now install the uuid-runtime package:

$ sudo apt install uuid-runtime

After the uuid-runtime package is install, we can generate a generate a single UUID by executing the following command in your terminal:

$ uuidgen

Following output will appear with a different UUID:

You can also generate time-based and hash-based UUIDs using the uuidgen command.

The below command will give time based UUID:

$ uuidgen -t

A random UUID can be obtained using the uuidgen with “-r”:

$ uuidgen -r

Generating Multiple UUIDs

To generate a list of UUIDs we can use a for loop.

Below command will generate 10 UUIDs randomly:

$ for i in {1..10}; do uuidgen; done

You’ll see 10 UUIDs printed to the screen:

To generate a custom number of UUIDs replace the value 10 with any number.

Conclusion

UUIDs are a convenient way of uniquely identifying resources in a globally unique manner. The “uuidgen” tool in Linux makes it easy to generate UUIDs, making it a useful tool for developers and system administrators. Whether you are working on a database, network interface, or other system, using UUIDs can help ensure that your resources are uniquely identified and accessible across multiple systems.

About the author

Kashif

I am an Electrical Engineer. I love to write about electronics. I am passionate about writing and sharing new ideas related to emerging technologies in the field of electronics.