Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to set something like a trigger on a file, so that everytime the file is changed a script or program will be executed?

I only found a mechanism for this within a shell script but would like to know if there is a mechanism for that on operating system basis (so that I don't have to manually run a background program). A solution on operating system basis would be a cron-job that runs every few seconds, but this does not look like an adequate solution to me.

It is for Debian, btw.

Thanks for help.

share|improve this question
up vote 6 down vote accepted

one of your options is the inotify subsystem of the linux kernel:

inotify is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications

but since inotify is kernel-land, you need something in user-space to actually use it:

The inotify cron daemon (incrond) is a daemon which monitors filesystem events and executes commands defined in system and user tables. It's use is generally similar to cron(8).

Gamin is a monitoring system for files and directories that independently implements a subset of FAM, the File Alteration Monitor. Running as a service, it allows for the detection of modifications to a file or directory. gam_server functions as a daemon for Gamin.

inoticoming - trigger actions when files hit an incoming directory

there was an answer to a similar question on askubuntu:

share|improve this answer
Just to let you know: I now use inotify in combination with incron, which works perfectly fine for me. I'm aware that incron is still in alpha phase but it does a really well job. Thank you very much for this great advise! – cyphorious Dec 2 '11 at 13:10

Another quick and dirty way to do this is to use inotifywait from the inotify-tools package (on fedora).

I like this method better because you can do it all from a single bash command line. I often use this when I'm writing small programs to see the results of what I just saved.

while [[ 1 ]]; do inotifywait -e modify <filename>; make && ./helloworld; done
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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