小編給大家分享一下如何實現(xiàn)自動清除日期目錄shell腳本,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)成立與2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元安寧做網(wǎng)站,已為上家服務(wù),為安寧各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220實現(xiàn)自動清除日期目錄shell腳本實例代碼
很多時候備份通常會使用到基于日期來創(chuàng)建文件夾,對于這些日期文件夾下面又有很多子文件夾,對于這些日期文件整個移除,通過find結(jié)合rm或者delete顯得有些力不從心。本文提供一個簡單的小腳本,可以嵌入到其他腳本,也可直接調(diào)用,如下文供大家參考。
1、腳本內(nèi)容
[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
以上是“如何實現(xiàn)自動清除日期目錄shell腳本”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
名稱欄目:如何實現(xiàn)自動清除日期目錄shell腳本-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://aaarwkj.com/article28/hcscp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、自適應(yīng)網(wǎng)站、搜索引擎優(yōu)化、域名注冊、做網(wǎng)站、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容