前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >Shell脚本文件批量创建与修改的方法

Shell脚本文件批量创建与修改的方法

原创
作者头像
用户8989785
修改2021-09-13 11:48:05
修改2021-09-13 11:48:05
1.3K00
代码可运行
举报
文章被收录于专栏:网站技术分享网站技术分享
运行总次数:0
代码可运行

一、脚本要求

1.所有操作在/python下

2.批量创建12个以py后缀结尾的文件,文件名中必须包含_hcip,文件名除了_hcip固定字符串外,文件名还包含8个小写随机的字符。

3.创建的12个文件后缀名改为大写的PY,固定字符串改为_hcie

二、脚本内容

代码语言:javascript
代码运行次数:0
复制
#!/bin/bash
##########################################################
#File Name:create_file.sh
#Version:V1.0
#Aurhor:
#Emali:
#Created Time:2021-06-15 02:56:59
#Description: create files & modify files
##########################################################
 
 
if [ -d /python ];then
   cd /python
else
   mkdir /python
   cd /python
fi
for i in {1..12}
do
   file_name=$(echo $RANDOM |md5sum |cut -c 1-8)
   touch ${file_name}_hcip.py
done
 
for files in $(ls /python)
do
     file1=$(echo $files |cut -d '_' -f1)
     mv $files ${file1}_hcie.PY
done

三、脚本运行结果

代码语言:javascript
代码运行次数:0
复制
[root@control python]# /scripts/create_file.sh 
[root@control python]# ll
total 0
-rw-r--r-- 1 root root 0 Jun 15 04:26 4272db00_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 51989a58_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 75075364_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 7a272319_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 7d76af2f_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 977e73d6_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 9e4386a0_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 a35d5337_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 b9cb6458_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 b9d3349e_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 c3e589a2_hcie.PY
-rw-r--r-- 1 root root 0 Jun 15 04:26 e4f82be8_hcie.PY

总结

到此这篇关于Shell脚本之文件批量创建与修改的文章就介绍到这了。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档