1833871 Members
1746 Online
110063 Solutions
New Discussion

Find command

 
SOLVED
Go to solution
Larry Scheetz
Advisor

Find command

I am using the following command and have a question.
0 * * * * /usr/bin/find /u03/oradata/archprod -mtime +1 -exec rm {} \;
This seams to be working but in the directory it is keeping two days worth of stuff. I want all log files older than one day to be removed. I look and there is currently files from 02/05/02 on on the hour of the script. Any suggestions on how to only keep one day (24 hours) of files?

Thanks
Larry
A Happy heart makes the face cheerful
6 REPLIES 6
George A Bodnar
Trusted Contributor
Solution

Re: Find command


-mtime +0 will do the trick.
A. Clay Stephenson
Acclaimed Contributor

Re: Find command

Hi:

You are telling find to find all files older the +1 days. What is bigger than 1? 2. Change to +0. Warning: always test your find's with a safe statement like -exec echo {} \; BEFORE doing the real thing will -exec rm {} \;
If it ain't broke, I can fix that.
John Palmer
Honored Contributor

Re: Find command

Try -mtime +0

Regards,
John
James R. Ferguson
Acclaimed Contributor

Re: Find command

Hi Larry:

A "day" to 'find' is a 24-hour period. If you want to refine your criteria further, you can touch a reference file and use the '-newer' option (negated or not, as necessary).

# touch -a -m -t 200202070700 /tmp/ref
# find /tmp -type f -newer /tmp/ref

Regards!

...JRF...
Steve Steel
Honored Contributor

Re: Find command

Hi


I found a reference to the mtime which suggests the following.

-mtime option looks at

-1 since yesterday ( as within 24 hours)
1 yesterday (between 24 and 48 hours old)
+1 before yesterday (48 hours or older)

Explanation of the argument n is explained in the expressions part of the man page for find(1) and your HP-UX Reference.

steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
harry d brown jr
Honored Contributor

Re: Find command

Write a perl script to look for the files.

http://www.fnal.gov/docs/products/perl/pod.new/5.00503/pod/perlfaq5.html#How_do_I_get_a_file_s_timestamp_



Also, you can get Gnu's find, which allows MINUTE searches:
http://www.gnu.org/manual/findutils-4.1/html_mono/find.html#SEC15


live free or die
harry
Live Free or Die