生成随机名字文本
要求: 生成10个, 每个文本文件个格式为: 随机小写字母_test.txt
vim random.sh
#!/bin/bash
random_dir=”/random”
create(){
for i in `seq 1 10`
do
cd $random_dir && touch `tr -dc “a-z”</dev/urandom |head -c 10`_test.txt
i=$(($i+1))
done
}
check(){
if [ -d $random_dir ];
then
create
else
mkdir $random_dir
create
fi
}
check
运行结果
bash random.sh
[root@localhost ~]# bash random.sh
[root@localhost ~]# ls /random/
ajwlubiblp_test.txt djsvpmwfnc_test.txt ivjltcfzxj_test.txt ohewvqusci_test.txt orrbxbgdar_test.txt
btnazfioyo_test.txt idtmjjeutb_test.txt ixiogqaffl_test.txt ornsjjwfvw_test.txt tggjzbboas_test.txt
[root@localhost ~]#