This question already has an answer here:

How can I register to event that let me know when specific file is read in linux?

Can implement in c or in bash /shell script

marked as duplicate by roaima, Mr Shunz, GAD3R, muru, sebasth Apr 16 at 14:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @roaima The purported dupe asks a different thing -- the title is misleading; please read the actual text of the question. This question was probably already asked a lot of times, but not there. – mosvy Apr 15 at 7:03
  • @mosvy the answers on the suggested dup are applicable here too. They say the same as your answer. – roaima Apr 15 at 7:17
  • No, they're not applicable. They don't show how to monitor whenever a read(2) is done, as in my example. And they're cluttered with a lot of confusing stuff: loggedfs, .bash_history, etc. As I said, there probably is a dupe for this, but not that. – mosvy Apr 15 at 7:21
  • How about unix.stackexchange.com/questions/207304/… for a less-confusing duplicate? – JigglyNaga Apr 16 at 11:59

Use inotify(7), inotify_add_watch(2) with IN_ACCESS, inotifywait(1), etc.

Example: In a window:

while read f; do echo "$f"; sleep 3; done </path/to/your/file

In another window:

inotifywait -me access /path/to/your/file
/path/to/your/file ACCESS
/path/to/your/file ACCESS
/path/to/your/file ACCESS
  • 3
    Looking in linux not Windows – eventsss Apr 15 at 7:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.