您好,登錄后才能下訂單哦!
這篇文章主要介紹如何使用shell創(chuàng)建日期目錄,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
需要在多個目錄中 (如: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
以上是“如何使用shell創(chuàng)建日期目錄”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。