一個(gè)shell小案例(創(chuàng)建日期目錄)
今天看到一個(gè)shell題目,正好拿來(lái)練練手
需要在多個(gè)目錄中 (如:beijing shanghai tianjin guangzhou 等等) 創(chuàng)建子目錄(以年份命名),然后進(jìn)入子目錄,新建目錄并以當(dā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
我的實(shí)現(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/
總計(jì) 0
- PowerShell中使用Get-Date獲取日期時(shí)間并格式化輸出的例子
- Shell腳本遍歷一個(gè)日期范圍實(shí)例
- perl與shell獲取昨天、明天或多天前的日期的代碼
- 獲取兩個(gè)日期間隔時(shí)間的shell腳本代碼
- PowerShell中iso8601格式日期和DateTime對(duì)象互轉(zhuǎn)實(shí)例
- linux shell實(shí)現(xiàn)轉(zhuǎn)換輸入日期的格式
- 判斷輸入的日期是否正確的shell腳本
- linux shell中 if else以及大于、小于、等于邏輯表達(dá)式介紹
- 一個(gè)不錯(cuò)的shell 腳本教程 入門(mén)級(jí)
- 利用shell獲取指定日期前N天的日期
相關(guān)文章
linux 隨機(jī)密碼生成工具mkpasswd詳解及實(shí)例
這篇文章主要介紹了linux 隨機(jī)密碼生成工具mkpasswd詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-04-04Linux 中糾正拼寫(xiě)錯(cuò)誤的Bash 命令方法
這篇文章主要介紹了Linux 中糾正拼寫(xiě)錯(cuò)誤Bash 命令的方法,需要的朋友可以參考下2018-03-03script_tool_for_linux.bash: Linux 環(huán)境下的 hosts 一鍵部署腳本
這篇文章主要介紹了script_tool_for_linux.bash: Linux 環(huán)境下的 hosts 一鍵部署腳本,需要的朋友可以參考下2016-04-04Shell腳本編程中常用的數(shù)學(xué)運(yùn)算實(shí)例
這篇文章主要介紹了Shell腳本編程中常用的數(shù)學(xué)運(yùn)算實(shí)例,包含最基本的加減乘除,還有質(zhì)數(shù)、偶數(shù)的判斷等,需要的朋友可以參考下2014-06-06利用shell腳本遍歷文件夾內(nèi)所有的文件并作整理統(tǒng)計(jì)的方法
今天小編就為大家分享一篇利用shell腳本遍歷文件夾內(nèi)所有的文件并作整理統(tǒng)計(jì)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-06-06編寫(xiě)B(tài)ash Shell通過(guò)gnuplot繪制系統(tǒng)性能數(shù)據(jù)圖的方法
這篇文章主要介紹了編寫(xiě)B(tài)ash Shell通過(guò)gnuplot繪制系統(tǒng)性能數(shù)據(jù)圖的方法,做到可視化數(shù)據(jù)收集,需要的朋友可以參考下2015-07-07