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:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}