Link to home
Start Free TrialLog in
Avatar of aixtutorial
aixtutorialFlag for United States of America

asked on

This is in RHEL 5.need a ascript

This is in RHEL..need a script  which shuld find all the files older than 4 hours and move it to a different folder

find /obiee/BI/xml/ -type f  -mtime +240 -exec mv -f {} /staging/obiee2/ \;

This command above ist working
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

four hours is +mtime 4

find /obiee/BI/xml/ -type f  -mtime +4 -exec mv -f {} /staging/obiee2/ \;
Woo, sorry should be +mmin 240
find /obiee/BI/xml/ -type f  -mmin +4 -exec mv -f {} /staging/obiee2/ \;

manpage:
 -mmin n       File's data was last modified n minutes ago.
ASKER CERTIFIED SOLUTION
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arnold
you could also use touch -t <fourhoursago> /tmp/testfile
where <fourhoursago> has the format YYYYMMDDHHMM
find /obiee/BI/xml -type f -newer /tmp/testfile
Avatar of Tintin
Tintin

If you have a lot of files and/or filenames with spaces in them, you should use

find /obiee/Bi/xml -type f -mmin +240 -print0 | xargs -0 -i mv -f {} /staging/obiee2

Open in new window

Hi

I agree with arnold.
-newer is more reliable.

This all depends on how you want to use it.
a four hourly cronjob can touch a file to update it's last run time at the end, then when it starts again, just point -newer to it.
That way you don't miss any files.

Please explain how -newer is more "reliable".

well, -newer will even use the seconds.
So if you want it to be exact, you don't want to miss files that were created in the 59 seconds leading up to the minute.

I also found differences with the output set using -newer compared -mtime or -mmin.
Perhaps a bug in the ubuntu 10 version of find.

It is just better to give it the exact time to start the search from.