How to delete files more than 30 minutes old

I just need the simplest way to create a shell script/cron
that will delete files once they are older then 5 mins or 30 minutes.
the files would be limited to one directory and all have the same ending prefix that will be uniq to
them. for examp  1233.tmp 1234.tmp 1235.tmp

Thanks


TroderAsked:
Who is Participating?
 
gheistCommented:
find . -type f -ctime +5m -name [0-9]+\.tmp -print | xargs -n 5 rm -f

each option
0
 
Kent OlsenData Warehouse Architect / DBACommented:


touch -t`date +%Y%m%d%H%M --date "30 min ago"` tmpfile
for file in /dir/*
do
[[ "$file" -ot tmpfile ]] && echo "$file is older"
done
rm -f tmpfile


That may work for you.  What's your host O/S?


Kent
0
 
gheistCommented:
1) it finds files
2) created so long ago
3) my guess for regex to match your filename examples

and finally - dlete five of them at a time.

What are you trying to accomplish by such a script ???
It will not help with disk space shortage. Open files take space until closed. If you post uname -a you will get info how to handle them
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
brettmjohnsonCommented:
gheist, you need to quote the regex filename pattern to prevent the shell
from expanding it.

find . -type f -ctime +5m -name "[0-9]+\.tmp" -print | xargs -n 5 rm -f

0
 
gheistCommented:
right ...
0
 
gheistCommented:
brett actually fixed my command line ....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.