一個shell小案例(創(chuàng)建日期目錄)
今天看到一個shell題目,正好拿來練練手
需要在多個目錄中 (如:beijing shanghai tianjin guangzhou 等等) 創(chuàng)建子目錄(以年份命名),然后進入子目錄,新建目錄并以當天的日期命名。
最終的效果是這樣的:
china/guangdong/
china/guangdong/shenzhen/2010/1206
china/guangdong/shenzhen/2010/1207
china/guangdong/shenzhen/baoan/2010/1206
china/guangdong/shenzhen/baoan/2010/1207
china/guangdong/shenzhen/baoan/guangming/2010/1206
china/guangdong/shenzhen/baoan/guangming/2010/1207
我的實現(xiàn):
#!/bin/bash read -p "PLEASE input country:" cou read -p "PLEASE input city:" city read -p "PLEASE input name:" name #echo "$cou,$city,$name" date=$(date +%Y) #echo $date date2=$(date +%m%d) # echo $date2 if [ -d "./$cou/$city/$name/$date/$date2" ];then echo "the dir is exit" else mkdir -p ./$cou/$city/$name/$date/$date2 fi
效果:
[root@localhost hbshell]# test.sh
PLEASE input country:china
PLEASE input city:hangzhou
PLEASE input name:hb
#[root@localhost hbshell]# ll china/hangzhou/hb/2011/0321/
總計 0
相關文章
script_tool_for_linux.bash: Linux 環(huán)境下的 hosts 一鍵部署腳本
這篇文章主要介紹了script_tool_for_linux.bash: Linux 環(huán)境下的 hosts 一鍵部署腳本,需要的朋友可以參考下2016-04-04利用shell腳本遍歷文件夾內(nèi)所有的文件并作整理統(tǒng)計的方法
今天小編就為大家分享一篇利用shell腳本遍歷文件夾內(nèi)所有的文件并作整理統(tǒng)計的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06編寫B(tài)ash Shell通過gnuplot繪制系統(tǒng)性能數(shù)據(jù)圖的方法
這篇文章主要介紹了編寫B(tài)ash Shell通過gnuplot繪制系統(tǒng)性能數(shù)據(jù)圖的方法,做到可視化數(shù)據(jù)收集,需要的朋友可以參考下2015-07-07