Logging of file and directory access is very helpful to keep track of changes that are happening to files and folders. This recipe will describe how to log user accesses.
inotifywait command can be used to gather information about file accesses. It doesn't come by default with every Linux distro. You have to install the
inotify-tools package by using a package manager. It also requires the Linux kernel to be compiled with inotify support. Most of the new GNU/Linux distributions come with inotify enabled in the kernel.
Let's walk through the shell script to monitor the directory access:
#/bin/bash #Filename: watchdir.sh #Description: Watch directory access path=$1 #Provide path ...