Solved

how to check if there has been file updates on linux

Posted on 2008-10-11
7
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22693799
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
ID: 22695153
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
ID: 22696877
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:omarfarid
ID: 22696895
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
ID: 22697665
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
ID: 22697669
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
ID: 22698639
Another option is to use FAM.

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

690 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