title: Inotifywait for large directories
body: <p>In the inotifywait man changes the following is stated</p>
  
  <blockquote>
    <p>-r, --recursive  Watch  all  subdirectories of any directories passed as arguments.  Watches will be set up recursively to an unlimited
    depth.  Symbolic links are not tra‐versed.  Newly created
    subdirectories will also be watched.</p>
    
    <p>Warning: If you use this option while watching the root directory of
    a large tree, <strong>it may take quite a while until all inotify  watches 
    are  established</strong>,  and  events will not be received in this time. 
    Also, since one inotify watch will be established per subdirectory, it
    is possible that the maximum amount
                  of inotify watches per user will be reached.  The default maximum is 8192; it can be increased by writing to
    /proc/sys/fs/inotify/max_user_watches.</p>
  </blockquote>
  
  <p>I take this to mean that every time <code>inotifywait</code> is called, there is a delay for large directories. Therefore, constantly monitoring a large directory with monitor function like so</p>
  
  <pre><code>inotifywait -m /home/user/Documents
  </code></pre>
  
  <p>is more efficient than manually looping through the directory like so (from an example in the man pages)</p>
  
  <pre><code>while inotifywait /home/user/Documents; do
   #Do Something for each file change
  done
  </code></pre>
  
  <p>as every iteration of the while loop you have to set up inotifywait again. But with the first option, I can't execute based on the return. Ideally what I want is a callback function like so</p>
  
  <pre><code>inotifywait -m --callback ./callback.sh /home/user/Documents
  </code></pre>
  
  <p>so <code>callback.sh</code> gets called each time with the return value of <code>inotifywait</code>. How would I implement this?</p>