主页 > 知识库 > 实现自动清除日期目录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脚本实例代码的相关信息资讯供网民参考!
  • 推荐文章