Over a million developers have joined DZone.

Monitor Directory For Changes

·
From http://www.refactory.org/s/monitor_directory_for_changes_time_based/view/latest

Checks if a directory's contents have been changed every 10 seconds


#!/bin/sh
 
check() {
    dir="$1"
    for="$2"
    chsum1=`digest -a md5 $dir | awk '{print $1}'`
    chsum2=$chsum1
 
    while [ $chsum1 -eq $chsum2 ]
    do
        sleep $for
        chsum2=`digest -a md5 $dir | awk '{print $1}'`
    done
 
    echo "$0: $dir changed." >&
}
 
check $*
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}