Run a command when a file is accessed

inotifywait

inotifywait --event {{access}} {{path/to/file}} && {{command}}

click the source code to copy install inotifywait on any operating system with command-not-found.com