黑松山资源网 Design By www.paidiu.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
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
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月10日
2024年10月10日
- 马小倩《落花A2HD3-HQCD》头版限量[低速原抓WAV+CUE]
- 343前动画师怒喷343糟糕管理层:纯纯的毒瘤
- 《生化2RE》12.31苹果Mac平台发售:现已登陆商店
- 《使命召唤21:黑色行动6》实机发售预告!体验史诗电影单人战役
- 《张雨生 不朽的歌声 黑胶2CD》[WAV/分轨][860MB]
- 《赵传 你过得还好吗 2017》[FLAC/分轨][350MB]
- 《流行新歌告诉你 36首经典金曲 2CD》[WAV+CUE][1GB]
- 王宏伟.2012-用我的心握你的手【太平洋影音】【WAV+CUE】
- 谢安琪.2006-K.SUS.2(EP)(2015金碟复刻版)【BanBanMusic】【WAV+CUE】
- 谢安琪.2005-KAY.ONE(2015金碟复刻版)【BanBanMusic】【WAV+CUE】
- 《勇敢小骑士》评测:是永无乡,亦是梦幻岛
- 《哈利波特:魁地奇锦标赛》:我们魔法学院自己的足球赛
- 《冰汽时代2》评测:看来这一切都是值得的
- 《蛋仔派对》翻糖壳壳皮肤图鉴
- 《蛋仔派对》斑马乐乐皮肤图鉴