婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 實現自動清除日期目錄shell腳本實例代碼

實現自動清除日期目錄shell腳本實例代碼

熱門標簽:益陽400電話申請辦理流程 400的電話一般從哪里辦理 怎么用百度地圖標注坐標 江西全自動外呼系統報價 上海機器人外呼系統哪家好 梧州防封電銷卡 春運地圖標注app 地圖標注人員分布 昆明電銷機器人價格

實現自動清除日期目錄shell腳本實例代碼

很多時候備份通常會使用到基于日期來創建文件夾,對于這些日期文件夾下面又有很多子文件夾,對于這些日期文件整個移除,通過find結合rm或者delete顯得有些力不從心。本文提供一個簡單的小腳本,可以嵌入到其他腳本,也可直接調用,如下文供大家參考。 

1、腳本內容

[root@SZDB ~]# more purge_datedir.sh  
#!/bin/bash 
# Author: Leshami 
# Blog : http://blog.csdn.net/leshami 
 
RemoveDir=/log/hotbak/physical 
dt=`date +%Y%m%d -d "3 day ago"` 
 
for subdir in `ls $RemoveDir`; 
do 
  if [ "${subdir}" \ "${dt}" ]; 
    then  
    rm -rf $RemoveDir/$subdir >/dev/null 
    echo "The directory $RemoveDir/$subdir has been removed." 
  fi 
done 

2、演示

[root@SZDB ~]# ls /log/hotbak/physical 
20141203 20141210 20141217 20141224 20141231 20150107 20150114 20150125 tmp.sh 
20141207 20141214 20141221 20141228 20150104 20150111 20150121 20150128 
 
[root@SZDB ~]# ./purge_datedir.sh  
The directory /log/hotbak/physical/20141203 has been removed. 
The directory /log/hotbak/physical/20141207 has been removed. 
The directory /log/hotbak/physical/20141210 has been removed. 
The directory /log/hotbak/physical/20141214 has been removed. 
The directory /log/hotbak/physical/20141217 has been removed. 
The directory /log/hotbak/physical/20141221 has been removed. 
The directory /log/hotbak/physical/20141224 has been removed. 
The directory /log/hotbak/physical/20141228 has been removed. 
The directory /log/hotbak/physical/20141231 has been removed. 
The directory /log/hotbak/physical/20150104 has been removed. 
The directory /log/hotbak/physical/20150107 has been removed. 
The directory /log/hotbak/physical/20150111 has been removed. 
The directory /log/hotbak/physical/20150114 has been removed. 
The directory /log/hotbak/physical/20150121 has been removed. 
 
[root@SZDB ~]# ls /log/hotbak/physical 
20150125 20150128  

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

您可能感興趣的文章:
  • 自動清除電腦垃圾及刪除windows默認共享盤符的批處理bat
  • mssql自動備份及自動清除日志文件服務器設置
  • MSsql每天自動備份數據庫并每天自動清除log的腳本

標簽:懷化 九江 河南 惠州 北京 亳州 新疆 贛州

巨人網絡通訊聲明:本文標題《實現自動清除日期目錄shell腳本實例代碼》,本文關鍵詞  實現,自動,清除,日期,目錄,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《實現自動清除日期目錄shell腳本實例代碼》相關的同類信息!
  • 本頁收集關于實現自動清除日期目錄shell腳本實例代碼的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 合水县| 西平县| 麻城市| 淳安县| 错那县| 龙江县| 荥经县| 宁晋县| 林芝县| 时尚| 阳曲县| 新巴尔虎左旗| 尖扎县| 广安市| 赤水市| 五华县| 廉江市| 平泉县| 兴义市| 阜新| 蕉岭县| 安图县| 宣武区| 革吉县| 呼和浩特市| 苗栗市| 德惠市| 巴彦县| 客服| 伊金霍洛旗| 通江县| 桦甸市| 鸡泽县| 高陵县| 库车县| 浦城县| 古交市| 吉木乃县| 成武县| 新津县| 宜宾市|