Monitor directory listing for changes? Monitor directory listing for changes? linux linux

Monitor directory listing for changes?


Most unix variants have an API for this, but it's not standardized. On Linux, there is inotify. On the command line, you can use inotifywait. Usage example:

inotifywait -m /path/to/dir | while read -r dir event name; do  case $event in    OPEN) echo "The file $name was created or opened (not necessarily for writing)";;    WRITE) echo "The file $name was written to";;    DELETE) echo "The file $name was deleted ";;  esacdone

Inotify event types are often not exactly what you're trying to notice (e.g. OPEN is very wide), so don't feel bad if you end up making your own file checks.


you can craft your own then if you don't want to install tools. Just an idea.Create a base line file of your directory using find command. Use a loop or cron job, find the directory using the same parameters, and check the new file against the base line file. Use a tool like diff to get the differences..

eg

find /path [other options] >> baseline.txt while true #or use a cron jobdo  find /path [same options] >> listing.txt  diff baseline.txt listing.txt  # do processing here...  mv listing.txt baseline.txt  # update the baseline.  sleep 60done