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]# 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM