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

如果想要修改crontab,一般做以下的几步就可以了 
将crontab 推到一个自定义的文件上 
crontab -l>;tmp 
编辑这个文件,做需要的修改 
vi tmp 
推回crontab 
crontab tmp 
 
 
 
#!/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
#-maxdepth 1 不删除子目录
# every minute delete *.txt file 3 minutes ago
echo \* \* \* \* \* find $DELDIR -maxdepth 1 $DELTIME -name $FILETYPE1 -exec rm -f {} \\\; >> crontab_del_3min
# every minute delete *.log file 3 minutes ago
echo \* \* \* \* \* find $DELDIR -maxdepth 1 $DELTIME -name $FILETYPE2 -exec rm -f {} \\\; >> crontab_del_3min
 
 
#write to crontab
crontab crontab_del_3min
 
#restart to crontab
/etc/init.d/crond restart
posted on 2014-09-18 08:59  欢跳的心  阅读(1222)  评论(0编辑  收藏  举报