Need script to remove files older than 5 minutes

Posted on 2007-03-25
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 500 total points
ID: 18788571
perl -e 'unlink $_ or warn $_ for grep  -M > 5/(24*60), <poe*.pid>'
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.


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

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…
Suggested Courses

617 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