Operating System - HP-UX
1834015 Members
2636 Online
110063 Solutions
New Discussion

"find" to know if a file change in less than 1 hour.

 
SOLVED
Go to solution
friki
Advisor

"find" to know if a file change in less than 1 hour.

Hi,

I need to know if a file of log is changing in less than 1 hour.
I found that with command "find file -mtime n " you have to know if a file change in n days. ¿another command o parameter for hours?

Thanks in advance.

11 REPLIES 11
Peter Godron
Honored Contributor

Re: "find" to know if a file change in less than 1 hour.

Hi,
temp file solution in:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1037903

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

So far you have not awarded any points !
Coolmar
Esteemed Contributor

Re: "find" to know if a file change in less than 1 hour.

find / -mtime -1

This starts the search at the root directory and looks for all files which were modified less than 1 day (24 hours) ago.
friki
Advisor

Re: "find" to know if a file change in less than 1 hour.

Yes, but i want to know only if this file change in one hour like max
thanks.-
Peter Nikitka
Honored Contributor
Solution

Re: "find" to know if a file change in less than 1 hour.

Hi,

the forum provides faster and more answers, when its previous work was rewarded by points by a question posting user...

Hint to your current question:
- create a stamp file via 'touch' having the 1-hour-back-timestamp
- use find ... -newer stampfile ...

The man-pages will give additional help for both commands!

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Robert-Jan Goossens
Honored Contributor

Re: "find" to know if a file change in less than 1 hour.

Hi,

# touch -m -t 200612151300 /var/tmp/first
# touch -m -t 200612151359 /var/tmp/last

# find . -type f \( -newer /var/tmp/first -a ! -newer /var/tmp/last \) -print

Regards,
Robert-Jan
Arturo Galbiati
Esteemed Contributor

Re: "find" to know if a file change in less than 1 hour.

Hi,
on line perl:
# To have the list of the file *.txt changed from 1 hours ago to now:
perl -e 'while (<*.txt>) { print "$_\n" if 1/24 > -M }'
to use this go in the directory where your file is and probably chnage .txt as .log.

HTH,
Art
friki
Advisor

Re: "find" to know if a file change in less than 1 hour.

Hi,
I have problems with following:

# touch -m -t 200612151300 /var/tmp/first
# touch -m -t 200612151359 /var/tmp/last

# find . -type f \( -newer /var/tmp/first -a ! -newer /var/tmp/last \) -print


Sometimes "find" return a file that is always changing and sometimes not return it and it should appear.


Thanks and regards.-


Peter Godron
Honored Contributor

Re: "find" to know if a file change in less than 1 hour.

Hi,
sorry to see you did not read the solution to exactly your problem, as given in my first link.
It specifies the temp file command and the find.

Remember that find command modifies some timestamps itself.
James R. Ferguson
Acclaimed Contributor

Re: "find" to know if a file change in less than 1 hour.

Hi:

> Sometimes "find" return a file that is always changing and sometimes not return it and it should appear.

I would expect this behavior when you use Robert's solution. There is nothing wrong with the solution.

If a file is actively being updated, then its metadata ('mtime', etc.) will periodically be updated. Hence, in the code posted by Robert, a file may fall outside of the scope you defined.

Unix does not maintain a file creation timestamp. Its modification ('mtime') is only equivalent to its creation timestamp when is is first opened for writing, and thus coincidently represents a creation marker.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: "find" to know if a file change in less than 1 hour.

Hi (again):

> Remember that find command modifies some timestamps itself.

To be clear, 'find' will only modify the *access* timestampe ('atime') of *directories* as it traverses them. For files in a directory to be examined ('stat()' in order to determine their modification, access timestamp, size, etc.) the directory must be read and hence the directory's last access time ('atime') will be changed.

The 'find' solution using '-newer' references the 'mtime' not the 'atime' of a file. Moreover, the solution shown *limited* results to files by using the '-type f' argument to the 'find'.

The manpages for 'find' will offer additional information, too.

Regards!

...JRF...
Regards!

...JRF...
friki
Advisor

Re: "find" to know if a file change in less than 1 hour.

Hi,

I resolved it adding one minute to initial time.

thanks.-