I have a script that scans a directory and does some maintenance on the files in it. Another process creates the files in the directory (10 - 30 files per day).

The script is called via a daily cron job . What I need is to trigger the script on an event (each time a new file is created in the directory). I prefer this rather than increasing the frequency of the cron job.

How can I do that? is there a command or a program to install?

Thanks in advance for any help.

5 Answers 5



inoticoming is a daemon to watch a directory with Linux's inotify framework and trigger actions once files with specific names are placed in there.

For example it can be used to wait for .changes files uploaded into a directory and call reprepro to put them into your repository.


incron is an "inotify cron" system. It works like the regular cron but is driven by filesystem events instead of time events. This package provides two programs, a daemon called "incrond" (analogous to crond) and a table manipulator "incrontab" (like "crontab").

incron uses the Linux Kernel inotify syscalls.

like cron, each user can edit its own incron tables.

  • 2
    Could you provide an example? Links to manual pages are welcome too, I could not find the one for incron, the inoticoming one is here.
    – Lekensteyn
    May 19, 2011 at 14:15
  • For incron see the manpages of incrond, incrontab and incron.conf May 19, 2011 at 14:22
  • 2
    I've edited your answer in a way I wanted to see it. I copied it from the packages descriptions, please be so extensive in the future when naming programs :)
    – Lekensteyn
    May 19, 2011 at 15:01

There is also a small program called iwatch - see the man page (this page is for Ubuntu precise (12.04), it has links to other ubuntu versions).

iwatch has the ability watch folders recursively (ie: subfolders too) and to send emails in response to file/directory events.


Another utility worth to know is fileschanged (man page here), that can monitor filesystem event on selected files or directories, for example the following command

fileschanged -s created -t1 $PWD

should monitor the current directory for file creation events, writing the name of the created file on stdout with a 1sec timeout.

fileschanged can watch folders recursively (as can iwatch as noted in another answer), unlike incron and inoticoming.

  • Thanks. And this even works with mounted CIFS Windows shares. Nov 22, 2022 at 13:57

inotify man page is located there

if you prefer python scripts, you can use pyinotify


As of 2023, I'd recommend looking at fswatch or guard, which both work on many platforms.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .