您的位置:首页 > 运维架构 > Linux

linux uuid

2016-03-28 00:00 417 查看

一、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