一個shell小案例(創(chuàng)建日期目錄)
今天看到一個shell題目,正好拿來練練手
需要在多個目錄中 (如: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
相關(guān)文章
linux shell之通過標(biāo)識測試文件系統(tǒng)屬性的方法示例
今天小編就為大家分享一篇關(guān)于linux shell之通過標(biāo)識測試文件系統(tǒng)屬性的方法示例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-04-04
Linux 通過 autojump 命令減少 cd 命令的使用的實(shí)現(xiàn)方法
這篇文章主要介紹了Linux 通過 autojump 命令減少 cd 命令的使用的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09
nagios 分發(fā)文件實(shí)現(xiàn)代碼
這篇文章主要介紹了nagios 分發(fā)文件實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-09-09
總結(jié)的7個shell字符串操作方法和實(shí)例分享
這篇文章主要介紹了總結(jié)的7個shell字符串操作方法和實(shí)例分享,包括長度獲取、查找位置、字符截取、匹配查詢等,需要的朋友可以參考下2014-07-07
Linux Shell在目錄下使用for循環(huán)結(jié)合if查找文件的巧用
今天小編就為大家分享一篇關(guān)于Linux Shell在目錄下使用for循環(huán)結(jié)合if查找文件的巧用,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03

