3

Basically I have a big directory (>10GB)(each subdir only has a few other subdirs) and want to do sth to any files that changes. I can't just go through all the files and check, because it takes to long and uses about 90% of my CPU :(.

This is how it looks basically:

dir
dir/subA
dir/subA/subAsubA
dir/subA/subAsubB
...
dir/subB
dir/subB/subBsubA
dir/subB/subBsubB
...
dir/SubC
dir/SubD
...

My thought was like this(file "test" in subBsubA chaged):

Check dir
 -> dir changed
   -->Check subA
      -> subA didn't change
   -->Check subB
      -> subB changed
      --> Check subBsubA
          -> subBsubA changed
             --> Check all files

But sadly the change of a file only effects the modification date of the direct parent directory :(

peterh
  • 11,875
  • 18
  • 85
  • 108
siiikooo0743
  • 326
  • 2
  • 9
  • Would [this](http://linux.die.net/man/7/inotify) help? – Aereaux May 29 '15 at 17:28
  • 1
    Do you want to do this in real time, or just as part of a periodic script that gets run? In the former case, the comment by @Aereaux definitely applies. In the latter, just use `stat` to check the "last modified date" of each file to see when it was last changed - perhaps stash that metadata away somewhere for comparison on the next run, or alternatively, just check to see if it was within some threshhold of the current date/time... – twalberg May 29 '15 at 17:40
  • http://stackoverflow.com/questions/511463/monitor-directory-for-changes. this may be helpful. – Prabhakaran May 29 '15 at 17:42
  • @twalberg Sth like `stat` would actually be a better solution, because I can't be sure if the script is running all the time a file may be changed. But like I said it takes to much time and resources to do this for all subdirectories, and I don't think it is possible to do this on the one parent directory only – siiikooo0743 May 30 '15 at 09:24

1 Answers1

4

As @Aereaux pointed out you probably need inotify, available in Linux since 2.6.13. See http://en.wikipedia.org/wiki/Inotify

There are inotify-tools available for command line usage as well. http://techarena51.com/index.php/inotify-tools-example/

SzG
  • 12,333
  • 4
  • 28
  • 41