SUMMARY: Script to remove old files

Charles Harvey (harvey@nmc8.chinalake.navy.mil)
Tue, 01 Apr 1997 15:32:51 -0800

Original question:

> I need a script to run on a regular basis which removes all old files
> beneath the current directory that contain 'MAILFORM' in their
> filename.
>
> I know this command: find . -mtime +45 -exec rm -f {} \; But it does
> not solve my problem because it erases ALL the older files. I only want
> to zap the MAILFORM files.
>
> Can someone please tell me how to work a pattern match into this command
> or else another way to accomplish my goal.
>
>

I know, It's in the man page for find. I couldn't make sense of it. Thanks for the response. I'm OK now. I have the correct syntax. Here are a few replies:

===================================================

find . -mtime +45 -name \*MAILFORM\* -exec rm -f {} \;
find . -name "*MAILFORM*" -mtime +45 -exec rm -f {} \;
find . -name '*MAILFORM*' -mtime +45 -exec rm -f {} \;

==========================================

I never use the -exec switch because it fires up rm for every single
file that's being erased. Try this:

find . -type f -mtime +45 -print | grep MAILFORM | xargs rm -f

xargs will create a nice long argument string of files to pass to rm.
Another advantage is if you'd like to find out what files were deleted; you
can redirect the grep to a file, mail it to yourself, and then feed that
file to xargs via stdin.

===========================================

All of this is available in the man page (man find). Be carefull with the
differences between GNU find and SunOS find.

============================================

I had to share this:

All opinions expressed herein are fictitious. Any resemblance with actual opinions, living or dead is purely concidental.

==============================================

A few of my heroes:

R A Lichtensteiger
Chistopher Haggard
Rich Kulawiec
Scott Parks
Sanjay Srivastava
Frank Pardo
David Perel
Jim Roy
Peter Utama
Charles Gagnon
Karl Vogel
Ruth H Woods
Michael Blandford