Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a uuid in shell script [duplicate]

Tags:

bash

shell

uuid

Is there a way to generate uuid in shell script, similar to $RANDOM, can i use $uuidgen to get a uuid, or do i need to install any package to generate a uuid in shell script

#!/bin/bash
echo $RANDOM
echo $uuid
like image 996
Sai Avatar asked May 16 '19 16:05

Sai


People also ask

How do I find unique ID in Linux?

You can find the UUID of all the disk partitions on your Linux system with the blkid command. The blkid command is available by default on most modern Linux distributions. As you can see, the filesystems that has UUID are displayed. A lot of loop devices are also listed.

What is Uuidgen?

Description. uuidgen, by default, generates a Universal Unique Identifier (UUID) on the standard output. The UUID is used to uniquely identifier an IDL interface definition.

Are UUID really unique?

No, a UUID can't be guaranteed to be unique. A UUID is just a 128-bit random number. When my computer generates a UUID, there's no practical way it can prevent your computer or any other device in the universe from generating that same UUID at some time in the future.


2 Answers

Have you tried

uuidgen

It's installed out-of-the-box on freeBSD systems like MacOS.

On Fedora, CentOS, and RHEL, get it from the util-linux package (CentOS6 has it in util-linux-ng). On debian, get it with sudo apt-get install uuid-runtime. On other linux systems, try looking for the e2fsprogs package.

like image 151
jeremysprofile Avatar answered Oct 16 '22 18:10

jeremysprofile


From this rather comprehensive article.
http://0pointer.de/blog/projects/ids.html
(btw, that's the blog of Lennart Poettering)

Linux offers a kernel interface to generate UUIDs on demand, by reading from /proc/sys/kernel/random/uuid

This is a very simple interface to generate UUIDs. That said, the logic behind UUIDs is unnecessarily complex and often it is a better choice to simply read 16 bytes or so from /dev/urandom

like image 38
Olesya Bolobova Avatar answered Oct 16 '22 19:10

Olesya Bolobova