要求:随机创建10个文件,文件名前缀要随机,包含hunk字符串,结尾是1-10,扩展名是.doc。
例如:mzE_hunk_8.doc,Ma_hunk_10.doc
[root@localhost ~]# vim file1.sh
#!/bin/bash
path1=/data/hunk
[ -d ${path1} ] || mkdir -p ${path1}
cd ${path1}
for i in `seq 1 10`
do
RANDOM1=`head -1 /dev/urandom |od -N 2 | head -1|awk '{print $2}'`
string1=`cat /dev/urandom |sed 's/[^a-zA-Z]'//g|strings -n 2 | head -1`
let n=${RANDOM1}%10+1
touch ${string1}_hunk_${n}.doc
done
[root@localhost ~]#bash file1.sh
[root@localhost ~]# ls /data/hunk/GHC_hunk_7.doc Mq_hunk_6.doc Rfa_hunk_1.doc tM_hunk_4.doc VY_hunk_2.docho_hunk_8.doc PA_hunk_1.doc slZ_hunk_4.doc Tq_hunk_5.doc zDmz_hunk_2.doc