How can I log all the events performed on a particular directory?
I want to log the entry of each directory modified within some time duration. I am using find . -type d -mmin -5
command.
In addition to this, I want to put more details, when any directory is moved to another place, I need to add the below log details, eg.,
directory "xyz" moved from "home/usr/xyz" => to "home/usr/documents/xyz"
Best Answer
If using
Linux
, you should tryinotifywait
command, it's designed to listen events on files or directories.You can use a
while
loop over that to filter the output.Moreover, it's very light : no need to
poll()
every N seconds, that's all the magic.See http://inotify-tools.sourceforge.net/