shell补-特殊玩法-生成随机字符串
方法1: md5sum
方法2:tr + /dev/urandom
方法3: 内置变量RANDOM ;
#方法1
[root@localhost ser]# openssl rand -base64 10
8/54arQpCmQ12Q==
[root@localhost ser]#
#方法2 必备
[root@localhost ser]# date +%N|md5sum ###给日期加密;可以写其他啥的;后面跟|cut -cl-8 取8位,
78d088f35ba6b917db746ae914a86a4c -
[root@localhost ser]#
##方法3 必备
[root@localhost ser]# echo $RANDOM
13608
[root@localhost ser]# echo $((RANDOM+1000000))
1003322
[root@localhost ser]#
##方法4 必备
[root@localhost ser]# tr -cd 'a-zA-z0-9' </dev/urandom|head -c10
###-cd
##-c 取反
##-d 删除
###</dev/urandom 把这个文件里的数据拿来处理
HxvgIfP4Pr[root@localhost ser]#
感觉是tr好用