linux下删除3分钟之前指定文件夹下的指定类型文件

时间:2014-09-18 09:38:33   收藏:0   阅读:210
#!/bin/sh
DELDIR="/root/crontab_test/test"
 
#3 minute ago
DELTIME="-mmin +3"
 
#delete file type
FILETYPE1="‘*.txt‘"
FILETYPE2="‘*.log‘"
 
 
#write to tmp file
rm crontab_del_3min -f
touch crontab_del_3min
 
# every minute delete *.txt file 3 minutes ago
echo \* \* \* \* \* find $DELDIR $DELTIME -name $FILETYPE1 -exec rm -f {} \\\; >> crontab_del_3min
# every minute delete *.log file 3 minutes ago
echo \* \* \* \* \* find $DELDIR $DELTIME -name $FILETYPE2 -exec rm -f {} \\\; >> crontab_del_3min
 
 
#write to crontab
crontab crontab_del_3min
 
#start to crontab
/etc/init.d/crond restart
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!