加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Shell编程面试题2_批量创建随机名称的文件

发布时间:2020-12-15 16:38:23 所属栏目:安全 来源:网络整理
导读:老男孩出的Shell编程企业面试题2: 使用for循环在/oldboy目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件,名称例如为: 1 2 3 4 5 6 [root@oldboyoldboy] #sh/server/scripts/oldboy.sh #ls coaolvajcq_oldboy.htmlqnvuxvicni_oldboy.ht

老男孩出的Shell编程企业面试题2:


使用for循环在/oldboy目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件,名称例如为:

1
2
3
4
5
6
[root@oldboyoldboy] #sh/server/scripts/oldboy.sh
#ls
coaolvajcq_oldboy.htmlqnvuxvicni_oldboy.htmlvioesjmcbu_oldboy.html
gmkhrancxh_oldboy.htmltmdjormaxr_oldboy.htmlwzewnojiwe_oldboy.html
jdxexendbe_oldboy.htmlugaywanjlm_oldboy.htmlxzzruhdzda_oldboy.html
qcawgsrtkp_oldboy.htmlvfrphtqjpc_oldboy.html

我的Shell脚本如下:

#!/bin/bash

html_dir=/oldboy/
for htmlnum in 1 2 3 4 5 6 7 8 9 10
do
        filename=`head -c 500 /dev/urandom | tr -dc a-z | head -c 10`_oldboy.html
        if [ -d $html_dir ]
        then
                cd $html_dir
                touch $filename
        else
                mkdir $html_dir
                cd $html_dir
                touch $filename
        fi
done

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读