See the uuidgen
program which is part of the e2fsprogs package.linux
According to this, libuuid
is now part of util-linux and the inclusion in e2fsprogs is being phased out.git
(On new Ubuntu systems, uuidgen
is now in the uuid-runtime
package.)github
To create a uuid and save it in a variable:dom
uuid=$(uuidgen)
On my Ubuntu system, the alpha characters are output as lower case and on my OS X system, they are output as upper case (thanks to David for pointing this out in a comment).ide
To switch to all upper case (after generating it as above):ui
uuid=${uuid^^}
To switch to all lower case:this
uuid=${uuid,,}
If, for example, you have two UUIDs and you want to compare them in Bash, ignoring their case, you can do a tolower()
style comparison like this:spa
if [[ ${uuid1,,} == ${uuid2,,} ]]
To add variety without adding external dependencies, on Linux you can do:.net
UUID=$(cat /proc/sys/kernel/random/uuid)
To propagate bad practices, on FreeBSD, under the linux compatibility layer (linuxulator?),code
UUID=$(cat /compat/linux/proc/sys/kernel/random/uuid)
References: