Ubuntu – Monitor folder contents changes

command linefilesystemmonitoring

I can monitor the content changes of a file using tail -f command

Is there a similar way of monitoring the changes of a directory structure the way tail -f monitors file?

I have a long running process that adds file to a certain path under a directory and i want to track the file incomings as it(or they) write(s) to the directories and sub directories.

Best Answer

The inotify kernel system is what you need.

  1. Install inotify-tools:

    sudo apt-get install inotify-tools
  2. Set up a watch:

    inotifywait /path/to/directory --recursive --monitor
  3. Sit back and watch the output.

From man inotifywait:

-m, --monitor
   Instead of exiting  after  receiving  a  single  event,  execute
   indefinitely.   The default behaviour is to exit after the first
   event occurs.
-r, --recursive
   Watch all subdirectories of any directories passed as arguments.
   Watches will be set up recursively to an unlimited depth.   Sym‐
   bolic  links  are  not  traversed.  Newly created subdirectories
   will also be watched.

You can use the --event option to watch for specific events, like creation, modification, etc.

Related Question