简体   繁体   中英

How can I detect if some file in a subdir changed?

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 :(

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM