linux uuid

一、uuid 生成

See the uuidgen program which is part of the e2fsprogs package.

According to this, libuuid is now part of util-linux and the inclusion in e2fsprogs is being phased out.

(On new Ubuntu systems, uuidgen is now in the uuid-runtime package.)

To create a uuid and save it in a variable:

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).

To switch to all upper case (after generating it as above):

uuid=${uuid^^}

To switch to all lower case:

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:

if [[ ${uuid1,,} == ${uuid2,,} ]]

2、减少对Linux依赖性的用法

To add variety without adding external dependencies, on Linux you can do:

UUID=$(cat /proc/sys/kernel/random/uuid)

To propagate bad practices, on FreeBSD, under the linux compatibility layer (linuxulator?),

UUID=$(cat /compat/linux/proc/sys/kernel/random/uuid)

References:

  • UUID on Wikipedia.

  • FreeBSD Bug #186187 - [linprocfs] [patch] emulate /proc/sys/kernel/random/uuid


你可能感兴趣的:(linux,uuid)