Monitor directory with inotify

You can use inotifywait to watch a directory (or a file for that matter) for changes and run some action when they happen.

A sample script, which watches for a new file to be created and prints only its name:

#!/bin/bash

inotifywait -m -e create --format %f /tmp/mytestdir | while read FILE
do
  echo "$FILE"
done
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s