–=使用/dev/urandom产生随即数字串或字符串===
产生随机的字符串
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9A-Za-z | head -c ${1:-10};echo
jM8dJgnFs1
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9A-Za-z | head -c ${1:-10};echo
05enzcqSzF
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9A-Za-z | head -c ${1:-10};echo
t9pDfywZdT
可以指定产生字符串的长度
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9A-Za-z | head -c ${1:-20};echo
u97bAsmkACWoHp6augVT
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9A-Za-z | head -c ${1:-20};echo
PPIxgO912ExeLQzLN4Xf
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9A-Za-z | head -c ${1:-20};echo
hzARVCuk2rXUOCfLyoGq
产生随即的数字串
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9 | head -c ${1:-10};echo
7717137957
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9 | head -c ${1:-10};echo
8602026301
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 0-9 | head -c ${1:-10};echo
8975427772
产生随即的小写字母串
[root@nezhdb01 tmp]# < /dev/urandom tr -dc a-z | head -c ${1:-10};echo
swdpelbzpw
[root@nezhdb01 tmp]# < /dev/urandom tr -dc a-z | head -c ${1:-10};echo
wrlhbpqxap
[root@nezhdb01 tmp]# < /dev/urandom tr -dc a-z | head -c ${1:-10};echo
pmixwihjkd
产生随即的大写字母串
[root@nezhdb01 tmp]# < /dev/urandom tr -dc A-Z | head -c ${1:-10};echo
HHHUIPZNPC
[root@nezhdb01 tmp]# < /dev/urandom tr -dc A-Z | head -c ${1:-10};echo
VSKBNJJDAF
[root@nezhdb01 tmp]# < /dev/urandom tr -dc A-Z | head -c ${1:-10};echo
SNPVXQTKGM
产生随即的字符串
[root@nezhdb01 tmp]# < /dev/urandom tr -dc ‘a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-10};echo
T&9nwxP/4@
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 'a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-10};echo
IvK{H^xSir
[root@nezhdb01 tmp]# < /dev/urandom tr -dc ‘a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-10};echo
CQAe^~AJZC
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 'a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-10};echo
m})PZs
长度不够可以指定长度
[root@nezhdb01 tmp]# < /dev/urandom tr -dc ‘a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-20};echo
Xox!X/q7Z#F2a~oE
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 'a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-20};echo
7G]rvxY@h&TA
[root@nezhdb01 tmp]# < /dev/urandom tr -dc ‘a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-20};echo
dq(3rx4KKBrR
[root@nezhdb01 tmp]# < /dev/urandom tr -dc 'a-zA-Z0-9~!@#$%^&(){}[];‘’/、’ | head -c ${1:-20};echo
Q%r}jxZTz&R@^C9
–使用base64加密生成随即字符串=====
生成的字符串数字、字母、特殊字符都有(特殊字符只有“/+=”)
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64
HboH10GR6Eh6hqpSDYHz7on526j9kcsiXjYsa1cIGWs=
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64
UuN68b9AhlpT21TmMTcADXz+QCGaTl9WzxDmCHi8pnc=
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64
mcyV5YBedHwnBJs3S7yy+DhDXtfdtDEmgjGzMejTNKI=
生成只有字母的串
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64 | tr -dc [a-zA-z];echo
IjPhSNHVEScwXgFJrvdZGcxqJGuFfOolBCs
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64 | tr -dc [a-zA-z];echo
RhTjNwxvcCigBEWRAltvIaSOKOPicdIOlTkZaDM
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64 | tr -dc [a-zA-z];echo
PpohxJfYbFxftrUjDtBdaXtcDlhYmwmYuOE
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64 | tr -dc [a-zA-z] |cut -c 1-10
NYfStFThZy
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64 | tr -dc [a-zA-z] |cut -c 1-10
bPtAucNqwx
[root@nezhdb01 tmp]# head -c 32 /dev/urandom | base64 | tr -dc [a-zA-z] |cut -c 1-10
QGbgXlKIpQ
生成只有数字的串
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | base64 | tr -dc [0-9];echo
1575681057544431
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | base64 | tr -dc [0-9];echo
84738254914846104391273
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | base64 | tr -dc [0-9];echo
55720871769217108400057121801740
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | base64 | tr -dc [0-9];echo
37461946578160233
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | base64 | tr -dc [0-9] | cut -c 1-10
4411146960
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | base64 | tr -dc [0-9] | cut -c 1-10
8929713120
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | base64 | tr -dc [0-9] | cut -c 1-10
9962758034
生成数字、字母、特殊字符组合的字符串
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | tr -dc ‘a-zA-z~!@#$%^&()[]’ |cut -c 1-10
Vc]EGXl#%Z
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | tr -dc 'a-zA-z~!@#$%^&()[]’ |cut -c 1-10
!EMDsoxHiy
[root@nezhdb01 tmp]# head -c 100 /dev/urandom | tr -dc ‘a-zA-z~!@#$%^&*()[]’ |cut -c 1-10
d&yTKKbJ^$