• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

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


0
Troder
Asked:
Troder
  • 4
1 Solution
 
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:
find . -type f -ctime +5m -name [0-9]+\.tmp -print | xargs -n 5 rm -f

each option
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now