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

When I write a LaTeX document, I find myself to press F6 in my editor to compile often. Or when I use SASS, I often type make to convert my .scss into .css.

Now I would like to let the machine do the dirty work and run make or something else every time a given file change.

So far I kept a terminal window open and pressed arrow-up and return. Or I used watch make, but that seems like an odd solution.

Is there a nice way on Linux to do something when a given file changes?

share|improve this question
up vote 4 down vote accepted

You're looking for inotifywait, part of inotify-tools. There are some examples of how to use it on the project's site but a simple approach is,

while true; do inotifywait code.cpp -e modify; make; done

the key part of which is,

inotifywait code.cpp -e modify

That command will wait until code.cpp is modified then exit. Put in the infinite loop and followed with make causes it to constantly rebuild after every modification.

Besides waiting on modify, you can wait on creation, deletion, access, opening, closing, and more. I highly recommend looking at the project examples and inotifywait man page for some other ideas on how it can be used.

share|improve this answer
That is exactly what I am looking for! – Martin Ueding May 1 '12 at 9:52

Have a look at incron, a cron-like package that responds to filesystem events, instead of time events. The package consists of a daemon (incrond) and a table manipulator (incrontab), analogous to the well-known crond/crontab pair of cron.

With incron, you could easily arrange to run make whenever particular files and/or directories are modified.

share|improve this answer
That seems a little overkill on the one hand, but on the other it is just the right tool. I'll have to check it out, maybe I can enable and disable it for each programming session. – Martin Ueding Apr 27 '12 at 17:18

Rather than watch make, how about watch ls? Then just make when the timestamp changes.

share|improve this answer
Well, make already checks the timestamps, so it is rather pointless to check the time and then let make check the time again. – Martin Ueding Apr 26 '12 at 7:27
Right but running make is more expensive than running ls. – Scott Wilson Apr 26 '12 at 10:06
And if my makefile is just two lines for that single .tex? Do you think that would be worth writing an ls parser? – Martin Ueding Apr 27 '12 at 17:17

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.