常用的Shell脚本编程——根据时间查找或者删除文件

#!/bin/bash
#定义时间变量
time1=`date -d last-day +%Y%m%d`
time2=`date -d "2 day ago" +%Y%m%d` 
time3=`date -d "3 days ago" +%Y%m%d`
time=`date +%Y%m%d`
#time20=`date -d "$(date +%Y%m)01 last month" +%Y%m`
#基于时间变量删除多余文件
find /app/dwetl/rDataDir/*/* -type d ! -name $time1 ! -name $time2 ! -name $time3 ! -name $time | xargs rm -rf 
find /app/dwetl/lDataDir/*/* -type d ! -name $time1 ! -name $time2 ! -name $time3 ! -name $time | xargs rm -rf 
find /app/etl/rDataDir/*/* -type d ! -name $time1 ! -name $time2 ! -name $time3 ! -name $time | xargs rm -rf 
find /app/etl/lDataDir/*/* -type d ! -name $time1 ! -name $time2 ! -name $time3 ! -name $time | xargs rm -rf 

你可能感兴趣的:(Shell)