一個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
我的實現:
#!/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
相關文章
linux shell之通過標識測試文件系統(tǒng)屬性的方法示例
今天小編就為大家分享一篇關于linux shell之通過標識測試文件系統(tǒng)屬性的方法示例,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-04-04
Linux 通過 autojump 命令減少 cd 命令的使用的實現方法
這篇文章主要介紹了Linux 通過 autojump 命令減少 cd 命令的使用的實現方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09
Linux Shell在目錄下使用for循環(huán)結合if查找文件的巧用
今天小編就為大家分享一篇關于Linux Shell在目錄下使用for循環(huán)結合if查找文件的巧用,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03

