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.

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.

  • 1
    inotify is for Linux, not OS/X – Stéphane Chazelas Jun 9 '16 at 18:27
  • @StéphaneChazelas that's a shame as I don't use OSX :D – likewhoa Jun 9 '16 at 18:30
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.

Your Answer

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

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