1855590 Members
3173 Online
104112 Solutions
New Discussion

More find help

 
SOLVED
Go to solution
Greg Stark_1
Frequent Advisor

More find help

Is there a way to find all files in a directory and below that are older than 1 hour? I have tried with mtime but it only apears to use 24 hour increments.

Thanks again,
Greg
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: More find help

Yes, you can use a combination of touch to create a file (myfile) with a specified time stamp (maybe 1 hour in the past) and then use the find -newer myfile option.

Man find and touch for details.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: More find help

Hi Greg:

Use the 'newer' option of 'find' with a reference file of your choice to achieve the granularity you need:

# touch -m -t 200202111130 /tmp/ref
# find /dir -type f -newer /tmp/ref

Regards!

...JRF...
S.K. Chan
Honored Contributor

Re: More find help

This should work. You need to create a "dummy" file to compare it with. Eg: right now it's 8.30am (feb 11).

# touch -t 02110730 compare
==> this will create an empty file timestanp is feb11 7.30
# find /opt -newer compare
==> do your find with the -newer option
Paula J Frazer-Campbell
Honored Contributor

Re: More find help

Hi Greg

A small sript will do what you require :-

ls -lR | awk '{print $6,$7,$8,$9}'

Will pick out the date and times of your file.

date | awk '{ print $2,$3,$4 }'

Will pull the same date format and by comparing one against the other then if date time field is greater that one hour then pick up file name and do what you wish.

Be careful as different dirs can have same file names.

You you neen further scripting help then let the forum know.

Paula

If you can spell SysAdmin then you is one - anon
Greg Stark_1
Frequent Advisor

Re: More find help

Thanks all for the quick response.

F.Y.I.
find and touch seemed to work ok but I had to use ! -newer to get files older than 1 hour.

Thanks again.
James R. Ferguson
Acclaimed Contributor

Re: More find help

Hi (again) Greg:

Yes, negating '-newer' is/was correct. This was my oversight, but one that will no doubt reinforce this technique for you! ;-)

Regards!

...JRF...