#!/bin/bash
filePath=/it_data2/
filePath1=/it_data3/
cd $filePath
ls filename1* -lrt --time-style="+%Y-%m-%d %H:%M %z" | awk ‘{print $6,$7,$9;}‘ | while read filename
do
mk_date=`echo $filename | awk ‘{print $1}‘`
mk_filename=`echo $filename | awk ‘{print $3}‘`
t1=`date -d "3 day ago" +%s`
t2=`date -d "$mk_date" +%s`
echo ‘==============:‘[ $t1 -gt $t2 ]
if [ $t1 -gt $t2 ]
then
rm $mk_filename
echo ‘REMOVE FILE ‘$filePath/$mk_filename
else
echo ‘‘
fi
done
cd $filePath1
ls filename2* -lrt --time-style="+%Y-%m-%d %H:%M %z" | awk ‘{print $6,$7,$9;}‘ | while read filename
do
mk_date=`echo $filename | awk ‘{print $1}‘`
mk_filename=`echo $filename | awk ‘{print $3}‘`
t1=`date -d "3 day ago" +%s`
t2=`date -d "$mk_date" +%s`
echo ‘==============:‘[ $t1 -gt $t2 ]
if [ $t1 -gt $t2 ]
then
rm $mk_filename
echo ‘REMOVE FILE ‘$filePath/$mk_filename
else
echo ‘‘
fi
done
原文地址:https://www.cnblogs.com/xl-892694298/p/11018822.html