2

I have already looked at this question and its answers How to log access to a specific folder and changes in its contents?, however I would like something more specific, so that it logs the access to one file, or a collection of them in different locations (not in the same folder). So that every time the file is opened, the location and name of that file is logged along with the date and time stamp. Modifications to these files should also be logged.

Any way of doing this? I am running Ubuntu GNOME 15.04.

2

inotifywait can do this. Install the package inotify-tools:

sudo apt-get install inotify-tools

Then run inotifywait like this:

inotifywait --timefmt "%F %T" --format "%T %w %e" --daemon --outfile </path/to/logfile> </path/to/file1> </path/to/file2> ...

It will log the date, time, file and the event that occurred.

More information: inotifywait manual page.

-1
man inotify 

Then check inotify-tools. Its in the repository so install via

sudo apt-get install inotify-tools

Copying From above wiki link

inotifywait - This command simply blocks for inotify events, making it appropriate for use in shell scripts. It can watch any set of files and directories, and can recursively watch entire directory trees.

  • Could you please provide instructions on how to use this tool, and perhaps give some example code which could allow for you to start monitoring a file. – user364819 Oct 10 '15 at 14:55
  • I upvoted @Eric answer, He has already provided an example command. – Amit Oct 10 '15 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy