1

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.

abnry
  • 175
  • Basically the same as http://unix.stackexchange.com/questions/6068/is-it-possible-to-find-out-what-program-or-script-created-a-given-file but that thread focuses on Linux-specific solutions. – Gilles 'SO- stop being evil' Jun 09 '16 at 23:10

2 Answers2

0

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.

likewhoa
  • 143
0

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.