Solved

how to check if there has been file updates on linux

Posted on 2008-10-11
7
460 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
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get maximum transfer speed over LAN 4 103
LINUX backups with VEEAM 8 115
error log using ftp 7 56
ignore other .htaccess 2 58
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

790 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