watcherd - Shell Listener for Directory Changes on Linux

watcherd directory change notification

In this article, I am going to tell you about shell directory listener called watcherd. Daemon watcherd will check the directory changes and execute specified commands or shell scripts.

Installing watcherd

On Ubuntu 16.04


$ wget

Unzip archive

$ unzip 

If you do not have unzip installed execute

$ sudo apt-get install unzip

And copy to /usr/bin/

$ sudo cp watcherd-master/watcherd /usr/bin/


Now we can execute with --help flag

$ watcherd --help
watcherd help

Let's create a directory called test and make watcherd working

$ mkdir test

Now start watcherd with simple parameters

$ watcherd -v -p ~/test -a "echo added %n" -d "echo deleted %n" -t "ls -l ~/test" 

A little hint about watcherd parameters

  • -v verbose output
  • -p ~/test path to directory
  • -a "echo added %n" execute "echo added" if any directory is created in path
  • -d "echo deleted %n" execute "echo deleted" if any directory is deleted in path
  • %n will be substituted with directory name or you can use %p to get a full path to the created or deleted directory
  • -t "ls -l ~/test" execute command after triggering
  • & run in background
watcherd start daemon

And check if it is running

$ ps ax | grep watcherd
watcherd running check

Now we can try to create a new directory called aaa in our test folder

$ mkdir test/aaa
folder add

As we can see after creating directory aaa watcherd executed 'echo added aaa', we received watcherd verbose message with adding a new directory and its full path and ls -l trigger output.

Now let's delete this directory and check the output

$ rm -r test/aaa
watcherd folder remove

We got the same output just with the echo deleted aaa. But instead of doing echo you can perform there any shell command or run any script.

This daemon can be very useful with web servers such as nginx or apache for monitoring new folders with websites, creating new configuration files and restarting web server.

Leave a Comment