网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

如何实现自动清除日期目录shell脚本-创新互联

小编给大家分享一下如何实现自动清除日期目录shell脚本,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

创新互联成立与2013年,是专业互联网技术服务公司,拥有项目成都网站建设、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元安宁做网站,已为上家服务,为安宁各地企业和个人服务,联系电话:028-86922220

实现自动清除日期目录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

以上是“如何实现自动清除日期目录shell脚本”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


新闻标题:如何实现自动清除日期目录shell脚本-创新互联
URL分享:http://bjjierui.cn/article/hcscp.html

其他资讯