Skip to content

Instantly share code, notes, and snippets.

@thewrongjames
Last active October 19, 2019 21:51
Show Gist options
  • Save thewrongjames/be3f7a17f66dbfe9633a1465769ae306 to your computer and use it in GitHub Desktop.
Save thewrongjames/be3f7a17f66dbfe9633a1465769ae306 to your computer and use it in GitHub Desktop.
Run a command on a file every time it changes, using inotifywait.
#!/bin/bash
if [ $# -ne 2 ]; then
echo Run a given command on a file when it is modified.
echo Usage: runonfileonchange command file
exit 1
fi
while inotifywait -e modify $2; do
$1 $2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment