Solved

how to check if there has been file updates on linux

Posted on 2008-10-11
7
456 Views
Last Modified: 2013-12-16
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
Comment
Question by:yosato_uk
  • 3
  • 2
  • 2
7 Comments
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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
 
LVL 48

Accepted Solution

by:
Tintin earned 125 total points
Comment Utility
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
 

Author Comment

by:yosato_uk
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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
 

Author Comment

by:yosato_uk
Comment Utility
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
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
Another option is to use FAM.

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now