×


Universally Unique Identifier UUID with uuidgen

Are you trying to generate a Universally Unique Identifier (UUID) with uuidgen?

This guide is for you.


Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Linux related Tasks.

In this context, we shall learn you the process to generate Universally Unique Identifiers (UUIDs).


More information about a universally unique identifier (UUID)?

Universally unique identifiers (UUIDs) are 128-bit numbers that are unique and are used to identify information in computer systems.

They are composed of 16 octets and represent 32 base-16 characters.

Moreover, the central authority does not issue it instead you can generate it independently and then use it across a given system without suspicion of duplicate.


How to generate a Universally Unique Identifier (UUID) with uuidgen?

This steps will show you the steps to generate UUIDs.

1. Generating a UUID

Often, the uuidgen command is already installed on Unix OS systems like Linux and macOS. In case, if it is not then you can install it through the package manager. On Ubuntu and Debian systems, run the below command to install the UUID-runtime package.

$ sudo apt install uuid-runtime

Here is the command to generate a single UUID that has no arguments.

$ uuidgen

2. How to generate Multiple UUID?

In order to generate multiple UUIDs, you would need to make use of shell scripting. You can use the for loop to execute the uuidgen command multiple times.

For instance, run the following command to generate 10 UUIDs.

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

As a result, you must see 10 UUIDs printed to the screen.


3. How to use UUID in Test Data?

If you wish to generate a list of 2 UUIDs per line that is comma-separated values (CSV), you would need to use the echo command to print two UUIDs during each iteration of the for a loop. For that, run the below command.

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

Also, you can generate data that looks like an email address by making a small tweak to the echo statement.

$ for i in {1..10}; do echo `uuidgen`@`uuidgen`.com; done

The output would be as below;

7de44050-9df4-43aa-b3b4-3b47eff8fc31@3052e93c-95d1-40f5-b468-3d4e06dd208b.com
cca71187-f666-46ff-81c6-eb3b72ff6972@30f4c9a8-712e-4f4c-ad3a-4b55ef85eee0.com
6ff086ad-493d-4b3a-8ed1-970239d7125b@8302d772-4deb-43d1-8901-0a3b4f747b55.com
f9813daa-6a8e-4543-8708-d42cefdda20a@d586854c-7df9-4046-89f8-51f960973afb.com
a7d9e43b-d2b1-4415-b73d-ff72b713e45f@a7c56c2c-df25-44bc-872d-a893f750b54d.com
0d1d13fe-777d-44d8-b1b2-302ca1e48aa1@7c2d8d6c-fa8b-4fa3-a0ef-8360aa42e730.com
f85d0772-22d2-43d0-8d71-4d6714c2bb20@fb4f74fe-f9f9-4e86-b31d-f148344a97e0.com
f46eb868-0a99-4291-98f2-19d95f1e9fbb@37ef072d-c515-4145-8b8a-edf32ec18bd2.com
eac4a63e-2646-427a-a892-f8027c2791ed@33daf102-2b5b-4070-88c5-261fe5d96cfa.com
d75f6720-b249-4395-bcd7-9ffe2c67cabb@457b04b4-3c15-4b77-aae2-9afd6803bcfe.com

However, the output won’t be a real email address, but you can tweak the output one more time, and swap the second uuidgen for a disposable email address domain. These won’t be a list of realistic-looking data, but it will be a list of the email addresses you could actually use or monitor in tests.

Here is the command for it;

$ for i in {1..10}; do echo `uuidgen`@mail.com; done

This time, the output would be as below;

4ca50929-520b-49f7-996d-e369be5d6232@mail.com
16deaeae-64bd-45f0-9f73-b32d41ca1bfb@mail.com
743701e8-0dd5-4851-8fd4-24d155755ddc@mail.com
adff0015-c535-431a-970f-98fdd1fc21db@mail.com
6516fcb3-e54f-4800-a6dc-11d50d756f28@mail.com
8a9c5252-bd0c-4c3b-a7c9-4b60ebcc4294@mail.com
eed94fd6-b075-493c-8d8e-3acae90d5629@mail.com
f4ab80c2-85ca-4722-a260-0f84c37051fd@mail.com
53ead1c0-cc70-410f-a91a-4a79b339fba2@mail.com
b208e103-d7f1-4f6d-838c-530d6339dce7@mail.com

Then to save this output to a file, append > /path/to/some/file to pipe the output.

$ for i in {1..10}; do echo `uuidgen`@mailinator.com; done > /tmp/emails.txt

Then you can use the cat command to view the file you just created.

$ cat /tmp/emails.txt

[Need urgent assistance with Linux related Installation and tasks? – We are here to help you.]


Conclusion

This tutorial will guide you the steps to generate Universally Unique Identifiers (UUIDs) with uuidgen.