shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。

[root@localhost wyb]# cat test10.sh 
#!/bin/bash

#使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件

dir=/root/wyb/test10/
[  ! -d  $dir  ] && mkdir -p  $dir


for i in `seq 10`

do

  touch $dir`echo $RANDOM|md5sum|cut -c 1-10`_oldboy.html

done
[root@localhost wyb]# bash test10.sh
[root@localhost wyb]# cd test10
[root@localhost test10]# ls
3fb16229e0_oldboy.html  5bf08cf5ce_oldboy.html  73e073e1e6_oldboy.html  860bafa69b_oldboy.html  c0b0067928_oldboy.html
512c517124_oldboy.html  7245bf5bea_oldboy.html  76f98bef45_oldboy.html  94a1245d85_oldboy.html  f37ace5e6a_oldboy.html
[root@localhost test10]# 

 

[root@localhost wyb]# cat xiugai.sh 
#!/bin/bash
#将test10目录下的文件oldboy全部改成oldgirl(用for循环实现),并且html改成大写。
#3fb16229e0_oldboy.html  5bf08cf5ce_oldboy.html  73e073e1e6_oldboy.html  860bafa69b_oldboy.html  c0b0067928_oldboy.html
#512c517124_oldboy.html  7245bf5bea_oldboy.html  76f98bef45_oldboy.html  94a1245d85_oldboy.html  f37ace5e6a_oldboy.html

cd test10
for i in `ls` 
do

   a=`echo $i|cut -c 1-10`
   mv  ${a}_oldboy.html   ${a}_oldgirl.HTML


done
[root@localhost wyb]# bash xiugai.sh 
[root@localhost wyb]# cd test10
[root@localhost test10]# ls
3fb16229e0_oldgirl.HTML  5bf08cf5ce_oldgirl.HTML  73e073e1e6_oldgirl.HTML  860bafa69b_oldgirl.HTML  c0b0067928_oldgirl.HTML
512c517124_oldgirl.HTML  7245bf5bea_oldgirl.HTML  76f98bef45_oldgirl.HTML  94a1245d85_oldgirl.HTML  f37ace5e6a_oldgirl.HTML
[root@localhost test10]# 

 

posted on 2016-09-06 22:59  王月波  阅读(4039)  评论(2编辑  收藏  举报

导航