Search code examples
linuxinotify

How can I exclude PATTERN from inotify/incron


I'm using incron to watch for events in a directory but I want to exclude some subdirectory or some filename PATTERNS.

Is there a way I can do this elegantly?


Solution

  • Incron doesn't support pattern filters, so you'll need to implement your own.

    A simple example for just one file extension could be:

    Incrontab:

    /watched/directory IN_ALL_EVENTS /usr/local/bin/incronfilter .pyc $# /bin/echo $@/$# $& $%
    

    incronfilter:

    #!/bin/bash
    
    ext=$1
    file=$2
    shift 2
    
    [ "$file" == "${file%$ext}" ] &&  $*
    

    Hope it helps.