Shell脚本实战之文件批量创建和修改
生活随笔
收集整理的這篇文章主要介紹了
Shell脚本实战之文件批量创建和修改
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Shell腳本實(shí)戰(zhàn)之文件批量創(chuàng)建和修改
- 一、腳本要求
- 二、腳本內(nèi)容
- 三、腳本運(yùn)行結(jié)果
一、腳本要求
1.所有操作在/python下
2.批量創(chuàng)建12個(gè)以py后綴結(jié)尾的文件,文件名中必須包含_hcip,文件名除了_hcip固定字符串外,文件名還包含8個(gè)小寫(xiě)隨機(jī)的字符。
3.創(chuàng)建的12個(gè)文件后綴名改為大寫(xiě)的PY,固定字符串改為_(kāi)hcie
二、腳本內(nèi)容
#!/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 ];thencd /python elsemkdir /pythoncd /python fi for i in {1..12} dofile_name=$(echo $RANDOM |md5sum |cut -c 1-8)touch ${file_name}_hcip.py donefor files in $(ls /python) dofile1=$(echo $files |cut -d '_' -f1)mv $files ${file1}_hcie.PY done三、腳本運(yùn)行結(jié)果
[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總結(jié)
以上是生活随笔為你收集整理的Shell脚本实战之文件批量创建和修改的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux的系统启动流程
- 下一篇: Linux的shell脚本实战之whil