Inotify
From Kyle's Wiki
inotify is a way for userspace programs to intercept kernel-based filesystem events.
Instant chown watch example
#!/bin/bash # This script watches my home directory like a cybernetic hawk DIR=/home/kyle OG=kyle:users # Normal chown will actually spawn more inotify events. # This means we have to only chown when we actually need to function selective-chown { FILE=$1 CURRENTOG=`stat -c %U:%G "$FILE"` if [ "$OG" != "$CURRENTOG" ]; then echo " actually chowning $FILE" chown $OG "$FILE" fi } # Scripts cant read inotifywaits output easily, and we need to be careful with spaces # I *think* the only two syscalls we care about are attrib and create inotifywait -rm -e attrib -e create --format=%w%f $DIR \ | while read file; do selective-chown "$file" echo Running selective-chown on $file done