I want a script to sleep unless a certain file is modifed/deleted (or a file created in a certain directory, or ...). Can this be achieved in some elegant way? The simplest thing that comes to my mind is a loop that sleeps for some time before checking the status again, but maybe there is a more elegant way?
Can a bash script be hooked to a file?
linux;shell;files;hook
On linux, you can use the kernel's inotify feature. Tools for scripting can be found there: inotify-tools.Example use from wiki:#!/bin/shEVENT=$(inotifywait --format '%e' ~/file1) # blocking without looping[ $? != 0 ] && exit[ $EVENT = MODIFY ] && echo 'file modified!'[ $EVENT = DELETE_SELF ] && echo 'file deleted!'# etc...