• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >linux shell > 实现自动清除日期目录shell脚本实例代码

实现自动清除日期目录shell脚本实例代码

作者:lqh 字体:[增加 减小] 来源:互联网

lqh 通过本文主要向大家介绍了shell脚本获取日期,shell脚本日期,shell 日期,shell 日期加减,shell 获取日期等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

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

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  
</div>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

</div>

您可能想查找下面的文章:

  • 实现自动清除日期目录shell脚本实例代码
  • 判断输入的日期是否正确的shell脚本

相关文章

  • Git 创建分支提交远程分支详解
  • linux 查找大目录和大文件的方法(推荐)
  • 一个下载网页图片的shell脚本
  • Shell中的循环语句for、while、until实例讲解
  • mysql源码安装脚本分享
  • Linux Shell脚本系列教程(五):数学运算
  • shell脚本学习指南[四](Arnold Robbins & Nelson H.F. Beebe著)
  • Shell脚本中实现把输入的密码转换为*(星号)的方法
  • 5个Shell脚本编程入门练习例子
  • linux链接编译详解

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • php编译安装常见错误大全和解决方法
    • linux下怎么解压.tar.gz .tar.bz2命令
    • Shell脚本实现查杀子进程、僵尸进程
    • Linux 中C语言getcwd()函数的用法
    • linux find命令之exec简单概述
    • Shell脚本实现批量下载网络图片代码分享
    • 使用shell脚本找出网站的空页面和404错误页面
    • Shell正则表达式之grep、sed、awk实操笔记
    • linux shell 字符串操作(长度,查找,替换)详解
    • 自动化下载并检测ftp文件备份的shell脚本

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有