首页 > 代码库 > linux下删除3分钟之前指定文件夹下的指定类型文件

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

#!/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

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