shell--使用for循环批量创建10个随机小写字字母加固定字符的.txt文件,并写另一个脚本批量修改为.html文件...

1:使用for循环在/tmp/file下批量创建10个文件每个文件包含十个随机字符加固定字符的.txt文件,执行脚本后查看/tmp/file获得如下结果

[root@test 30]# ls /tmp/file/
bhfhddagkd_test.txt  ecaajfbekf_test.txt  hbgbjciekh_test.txt
cieehgffkd_test.txt  faghebiike_test.txt  ijaddfacka_test.txt
dcehifffkf_test.txt  fdaefebekc_test.txt
dgdacjfeka_test.txt  gfagbdbbka_test.txt

    解答:

file(){
filename=`uuidgen|tr '0-9-' 'a-z'|cut -c -10`
}
dir=/tmp/file
[ -d "$dir" ] || mkdir -p /tmp/file
for((i=1;i<=10;i++));do
    cd $dir
   file
   touch ${filename}_test.txt
done

2.在上题的基础上,将*_test.txt改为*_web.html格式,完成效果如下

[root@test 30]# ls /tmp/file/
bhfhddagkd_web.html  ecaajfbekf_web.html  hbgbjciekh_web.html
cieehgffkd_web.html  faghebiike_web.html  ijaddfacka_web.html
dcehifffkf_web.html  fdaefebekc_web.html
dgdacjfeka_web.html  gfagbdbbka_web.html

解答:

dir=/tmp/file
if [ -d "$dir" ];then
  cd $dir
 else
  echo "error"
fi
for i in `ls *.txt` ; do
  file_new=`echo $i|cut -c -10`
  mv $i ${file_new}_web.html
done

 

转载于:https://www.cnblogs.com/ExzaiTin/p/8005913.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值