Skip to content.
Joe Heaton's Webzone
🥐 ☕
Online since 2011

Run for every updated file

Using inotifywait to watch for file changes recursively in the current directory. I use $CHECK to ignore unwanted directories and filetypes.

#!/bin/bash

inotifywait -r -e close_write,moved_to,create -m . |
while read -r DIR EVENT FILE; do
    CHECK="$( echo "${DIR}${FILE}" | egrep -v '^\./(\.git|\.sass-cache|node_modules|public|static)' | egrep -v '\.(tmp|css)$' )"

    if [ "$CHECK" ]; then
        echo "Change in ${DIR}${FILE}"

        # This is what gets run
        make dev
    fi
done

Install inotify-tools on both Debian and CentOS.

avatar
Joe Heaton

Email: [email protected]

Web:

Joe’s technology-focused murmurings.
comments powered by Disqus

Settings!