Shell脚本实战之文件批量创建和修改
生活随笔
收集整理的這篇文章主要介紹了
Shell脚本实战之文件批量创建和修改
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Shell腳本實戰之文件批量創建和修改
- 一、腳本要求
- 二、腳本內容
- 三、腳本運行結果
一、腳本要求
1.所有操作在/python下
2.批量創建12個以py后綴結尾的文件,文件名中必須包含_hcip,文件名除了_hcip固定字符串外,文件名還包含8個小寫隨機的字符。
3.創建的12個文件后綴名改為大寫的PY,固定字符串改為_hcie
二、腳本內容
#!/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三、腳本運行結果
[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脚本实战之文件批量创建和修改的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux的系统启动流程
- 下一篇: Linux的shell脚本实战之whil