Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Need script to remove files older than 5 minutes

Posted on 2007-03-25
Medium Priority
Last Modified: 2013-11-17
I need a script that will look at certain files and if the file is over 5 minutes old, remove it.  
The files are located in /var/tmp
The file names can vary but always start with "poe" and ends with ".pid" so the script should look for files named "poe*.pid".  An example name would be "" or "".
I will be running this via cron on a IBM AIX machine.

Any help would be appreciated.
Question by:9thTee
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 19

Expert Comment

ID: 18788367
find /tmp -name poe*.pid -mmin 5 -exec '/bin/rm -f {} ;'

Author Comment

ID: 18788412
Unfortunately, it appears that IBM AIX does not have the -mmin parameter for find...
I get: find: 0652-017 -mmin is not a valid option.

Any ideas?
LVL 84

Accepted Solution

ozo earned 2000 total points
ID: 18788571
perl -e 'unlink $_ or warn $_ for grep  -M > 5/(24*60), <poe*.pid>'
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.


Author Comment

ID: 18788657
ozo, I am not sure what your perl script should do.  Can you please explain?

LVL 48

Expert Comment

ID: 18789459
ozo's Perl script does what you requested, although I'd change it to specify the path, ie:

perl -e 'unlink $_ or warn $_ for grep  -M > 5/(24*60), </var/tmp/poe*.pid>'

Removes all /var/tmp/poe*.pid files that are older the 5 minutes.

BTW, why did you post an AIX question in the Linux group?  As you saw from the first answer, GNU find (and all GNU versions of common commands) has very useful extensions like the mmin.

Author Comment

ID: 18789811
Ahhh, ok, it does work.  I just did not see something that said delete...

I am running AIX 5.1L which is AIX affinity with Linux.  I post in Linux area (in addition to AIX) because nearly all Linux suggestions works on AIX.  Since there are more Linux folks out there than AIX, I usually get faster responses when I post in the Limux area.

LVL 48

Expert Comment

ID: 18789828
Hmm.  Interesting that you don't have GNU find on your AIX system them.

Remember that in Unix, delete = rm which is really unlink.

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question