- [Instructor] Hello and welcome to
the next video of section eight.
Logging access to files and directories.
In the previous video we've learned
about monitoring command outputs with watch.
In this video, we'll see how to log access
to files and directories.
Logging a file and directory access is very helpful
to keep a track of changes that happens
to files and folders.
This section will describe how to log such accesses.
The inotify wait command can be used
to gather information about file access.
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 Junior Linux distributions
come with inotify enabled in the kernel.
Let's walk through the Shell script
to monitor the directory access.
The previous script will log events,
create, move, and delete files and folders
from the given path.
The -m option's given for monitoring
the changes continuously rather than going
to exit after an event happens.
And -r enables a recursive watch of the directories.
Symbolic links are ignored.
Finally -e specifies the list of events to be watched.
And -q is to reduce the verbose messages
and print only the required ones.
The output can be redirected to our logfile.
We can add or remove the event list.
Important events available are as follows.
Access, when a read happens to a file.
Modify, when a file contents are modified.
Attrib, when metadata is changed.
Move, when a file undergoes a move operation.
Create, when a new file is created.
Open, when a file undergoes an open operation.
Close, when a file undergoes a close operation.
Delete, when a file is removed.
Awesome.
We've successfully learned about logging access
to files and file directories.
In the next video we'll learn
about logfile management with logrotate.