思路一:
echo $RANDOM|md5sum |tr "[0-9]" "[a-j]"|cut -c 2-11
RANDOM: linux内置的随机数变量 默认是5个
md5sum :使用MD5加密,变成随机的字母
tr :替换。把0-9 替换成a-j
cut :截取出2-11位
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #!/bin/sh 2 3 4 [ -d "./test" ] || mkdir -p ./test 5 for n in `seq 10` 6 do 7 touch ./test/$(echo $RANDOM|md5sum |tr "[0-9]" "[a-j]"|cut -c 2-11)_oldboy.html 8 done
openssl rand 用于产生指定长度个bytes的随机字符。
-base64 / -hex 对随机字符串进行base64编码或用hex格式显示
#!/bin/sh path=./test [ -d "${path}" ] || mkdir -p ${path} for n in `seq 10` do random=$(openssl rand -base64 40 |sed 's#[^a-z]##g'|cut -c 2-11) touch ${path}/${random}_oldboy.html done
openssl rand -base64 40 |sed 's#[^a-z]##g'