Install inotify-tools on Debian based systems:
root@host:~# apt-get install inotify-tools
Watch a file or directory – recursively – for changes until a given timeout is reached of CTRL+Ctrl is pressed. Display a set of statistics on the monitored filesystem objects. In this example the directory /tmp
is watched for 60 seconds:
root@host:~# inotifywatch -t 60 -r /tmp Establishing watches... Finished establishing watches, now collecting statistics. total access modify close_write open create delete filename 159 146 9 1 1 1 1 /tmp/
Use the -z
command line option in order to display all rows and columns, even if the counters there are zero.
Watch a file or directory for a specific event. In this example the file /etc/hosts
is monitored for an event from the close
system call. This event is triggered in a second shell with a simple call of cat /etc/hosts
:
root@host:~# inotifywait -e close /etc/hosts Setting up watches. Watches established. /etc/hosts CLOSE_NOWRITE,CLOSE root@host:~# echo $? 0
Obviously the inotifywait
command is best suited for the use within (shell) scripts in order to trigger a specific behaviour upon the occurance of a certain set of filesystem events.