File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to find out if any files under directory recursively modified?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to write a UNIX command to indicate whether any files under a subdirectory have been modified in the last 24 hours. I need it to recurse within directories as the one changed file could be many levels down. That part is easy:


The thing is this is on the slow side because it has to go through the entire directory structure. I only need a boolean true/false answer. I'd like it to stop once it finds a modified file rather than continue compiling the list. Any thoughts on a way to accomplish this?
 
Ifteqar Ald
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can directly execute that command by going to the particular directory that will save execution time
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know which directory (if any) has a modified file though. If I did, I wouldn't need to run the command. If there are no matches, I understand UNIX having to look at each file. If there is a match, I feel like there should be a way to stop looking.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Untried, and a bit of a hack, but would it be possible to run a script that would kill the find itself while writing output somewhere that you could look at? Something like:


Where myScript might be something like:
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew,
I read about that hack but it adds so much complexity. Especially since I have scores or hundreds of these commands running at once (and then repeated for different directories).

It's actually a non-issue. I had started timing yesterday and found a big directory takes "at least 15 seconds." Turns out it takes 20.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A co-worker answered my question:


This runs 3-5 times faster than the original. It's hard to say exactly how much faster since each time I run it the command runs faster (presumably less disk lookups).
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't work unless the top level directory is the one modified. For example, suppose I have /a/b/c. If I modify a, it works as I expected. If I modify c, it returns c. I'm thinking I have to ladd some code to look for the level of directory I want.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17624
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the filesystem, modifying a file in a directory would percolate timestamps upwards so that the parent directories would show the timestamp of the latest file modification under them.

I think probably a straight "find" can be set up to do everything, with, perhaps the help of its "printf" options, but if not, the next best thing would probably be to let find scan for files, printf out their directory paths, and "uniq" the results.

As far as the stopping part goes, I doubt that the actual timestamp checking is going to be much overhead, although if you have to do text processing to pare down returned filepaths, that could add up.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic