How to Generate UUID in Linux

UUID (Universally Unique identifier) is a 128-bit unique number standardized by the Open Software Foundation. This number is universally unique and really impossible for a user to guess.

This tutorial shows how to generate UUID in Linux using uuidgen command line utility tool.

Generate UUID in Linux

Most of the Linux/Unix system supports the command line utility tool uuidgen to generate the UUID. If the package is unavailable install using apt install uuid-runtime command.

Uuidgen can generate random-based, time-based and hash-based UUIDs. Random based UUIDs is sufficient in most cases.

Simply executing uuidgen generates a random UUID.

You can use the -t flag along with uuidgen to generate a UUID based on system time. In the same way uuidgen command with option -r generates the random UUID based mostly on random bits.

Followings are the some example to generate UUIDs.

To create a random UUID, use the following command:

$ uuidgen

output:

9c79364e-99e1-42a8-ada1-86c31ad1fa76

To generate time based UUID, run:

uuidgen -t

Use the command uuidgen with the option -r to generate random UUID.

$ uuidgen -r

To generate hash based UUID use --md5 or --shal with --namespace <namespace>.

Conclusion

In this tutorial, we learned how to generate UUID in Linux. Finding UUID in Linux pretty easy, which is commonly required when it to comes to mount storage devices in fstab file.

1 thought on “How to Generate UUID in Linux”... add one

  1. I couldn't find any direct package for `uuidgen` in Fedora, so I prefer Python to make this happen,
    ```
    alias uuidgen='python -c '\''import uuid; print(uuid.uuid4())'\'''
    ```

    Reply

Leave a Comment