I would like to know which files in my system I access most often, as a gauge of how important they are. I know the OS records the last time the file was accessed. Is there someone way to log in a text file each time the file is accessed, possibly on an hourly or daily timescale? I suspect I could use a chron task but I am not very familiar with using it. I would prefer an OS X solution.
You can use inotify. See example code below.
#!/bin/sh src_path=/directory/path/to/monitor inotifywait --format '%:e %w%f' -e modify,delete,create \ --exclude '^.+(jpe?g|gif|ico|png|svg|pdf|pptx?|swpx|swp)$' \ -m -r "$src_path" | \ while read watched_filename EVENT_NAMES; do case "$watched_filename" in MODIFY) echo "$EVENT_NAMES has been modified" ;; CREATE) echo "$EVENT_NAMES has been created" ;; DELETE) echo "$EVENT_NAMES has been deleted" ;; *) echo "Unknown event, exiting";break esac done
You can modify the script to do all kinds of things like send you an SMS on a MODIFY event.
Here is a nice post about fswatch and inotify. I am not very familiar with fswatch however I use inotifywatch all the time and it sounds like what you're looking for.