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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
find is your best best, eg:

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

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?

10 Holiday Gifts Perfect for Your Favorite Geeks

Still have some holiday shopping to do for the geeks in your life? While toys, clothing, games, and gift cards are still viable options for your friends and family, there’s more reason than ever to consider gadgets and software.

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.
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?

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
Another option is to use FAM.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.