天天看点

shell 获取随机字符串(可指定长度)

# 1. use head to read first 16 Bytes from /dev/urandom
# 2. use od to display data in hexadecimal format (do not display address offset)
# 3. use tr to remove any extra spaces
$ head -c 16 /dev/urandom | od -A n -t x | tr -d ' '
2dbee3ebce1fd1d0dc5fa1134a7146f2
           

  注意:此处的 16 表示 16 个字节,而 1 个字节需要两个 16 进制位表示,因此结果是 32 位长度的字符串

继续阅读