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 位長度的字符串

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章