• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

how to check if there has been file updates on linux

Hi all

This might be a very basic question but I can't find the solution... I am looking for a simple way to check, on the Linux shell, whether there has been an update or access to the files *at all* in a certain directory (recursively) in the last xx mins, hrs etc. I would only need the answer yes or no, and would like to do it quickly: it would suffice if a command/script returns 'yes' when a single file has been found that has been updated recently, and stops.

'find -atime/-mtime' or 'test -e' comes to my mind but the former is a bit of an overkill, and for the latter, I don't really know how I could use it for the existence of 'a file updated recently'.

Advice would be appreciated.

Yo
0
yosato_uk
Asked:
yosato_uk
  • 3
  • 2
  • 2
1 Solution
 
omarfaridCommented:
you may develop a shell script that will prompt you for a date after which you want to check if any file was changed. Then you create a file with that date in a certain dir then use the fund command with the -newer option to see if there is a file in that dir newer than that file.

To create a file with a specific date and time use touch, for the exact format please see man touch

If find returns one ore files then you reply yes otherwise no
0
 
TintinCommented:
find is your best best, eg:



if [ -n "$(find /some/dir -amin -5)" ]
then
     echo "Files accessed in the last 5 minutes"
fi

Open in new window

0
 
yosato_ukAuthor Commented:
Thanks omafarid and tintin. test -n I didn't know, and this works fine, but I reckon this is not exactly what I wanted. I may be being kind of paranoid, given my file server is not large, but I do not want to do an exhaustive search. Isn't it possible to make the script stop & return yes immediately after the first file that was updated xx mins ago has been found?

Yo
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
omarfaridCommented:
How frequent you will be running the job to check if any file changed or accessed? If you do it frequent and there is hardly any change then I think the kernel cache for such info in memory will make faster and hence less load on the system.
0
 
yosato_ukAuthor Commented:
thanx omarfarid, i think i am just being curious, basically. isn't there a way to make 'find' -- or anything else of that sort --- interrupted when it encounters a file matching a certain condition?

Yo
0
 
omarfaridCommented:
Well, if you can log the output of file to a file and one that file contains at least one line then you kill the find command
0
 
TintinCommented:
Another option is to use FAM.

See http://oss.sgi.com/projects/fam/faq.html
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now