inotify-tools

inotify-tools is a C library and a set of command-line programs for Linux providing a simple interface to inotify. These programs can be used to monitor and act upon filesystem events. A more detailed description of the programs is further down the page. The programs are written in C and have no dependencies other than a Linux kernel supporting inotify.

inotify-tools 3.13 is the latest version, released on the 1st of January 2008.

Quick links: mailing list, download, Sourceforge project page, e-mail author, e-mail maintainer, libinotifytools API docs.

  1. Getting inotify-tools
  2. News
  3. Info
  4. Related Software

Getting inotify-tools

You can download inotify-tools and compile and install it the usual way.

Thanks to the hard work of a few people, some lucky users can also obtain inotify-tools through their distribution's package manager. If your distribution is listed here but does not have the most up-to-date version, you can try pestering the listed package maintainer. If your distribution is not listed here but it does provide inotify-tools, let me know!

Fedora

inotify-tools is available through the Fedora Extras repository. Just do:

yum install inotify-tools

Adel Gadllah is the Fedora package maintainer.

Gentoo

inotify-tools is available in Gentoo's official portage tree. It may be masked, in which case read the "MASKED PACKAGES" section of the man page for emerge, then unmask it. Then you can simply:

emerge inotify-tools

Wolfram Schlich is the Gentoo package maintainer.

Debian/Ubuntu

inotify-tools is available in Debian's official repositories. You can install it by:

apt-get install inotify-tools

Ryan Niebur is the Debian package maintainer.

ALT Linux

inotify-tools is available in the Sisyphus repository. With ALT Linux Sisyphus you can install by the following command:

apt-get install inotify-tools

Igor Zubkov is the ALT Linux Sisyphus package maintainer.

Frugalware Linux

inotify-tools is available in Frugalware Linux. It can be installed with the following command:

pacman-g2 -S inotify-tools

Priyank Gosalia is the Frugalware Linux package maintainer.

Everyone Else

Download inotify-tools source, then compile and install:

./configure --prefix=/usr && make && su -c 'make install'

News

Be notified of new releases by this RSS feed, or by subscribing on Freshmeat.

1 January 2008: inotify-tools 3.13 released. Changes:

24 November 2007: inotify-tools 3.12 released. Changes:

18 September 2007: inotify-tools 3.11 released. Changes:

5 May 2007: inotify-tools 3.10 released. Changes:

29 April 2007: inotify-tools 3.9 released. Changes:

18 February 2007: inotify-tools 3.8 released. Changes:

4 February 2007: inotify-tools 3.7 released. Changes:

17 December 2006: inotify-tools 3.6 released. Changes:

4 December 2006: inotify-tools 3.5 released. Changes:

3 December 2006: inotify-tools 3.4 released. Changes:

31 October 2006: inotify-tools 3.3 released. Changes:

29 October 2006: inotify-tools 3.2 released. Changes:

28 October 2006: inotify-tools 3.1 released. Changes:

27 October 2006: inotify-tools 3.0 released. Changes:

4 October 2006: inotify-tools mailing list created, also intended for general inotify discussion.

3 October 2006: inotify-tools 2.6 released. Changes:

2 October 2006: inotify-tools 2.5 released. Changes:

9 September 2006: inotify-tools 2.4 released. Changes:

14 August 2006: inotify-tools 2.3 released. Changes:

6 July 2006: inotify-tools 2.2 released, and project moved to Sourceforge, yippee!

Info

inotify-tools is written by Rohan McGovern (mail, web). The current version of inotify-tools is considered stable. As of 6th of June 2009 the project is maintained by Radu Voicilas (mail).

If you have a question which others could benefit from the answer to, or if you want to make suggestions about future development of inotify-tools, send mail to the mailing list. General queries about development with inotify are also welcome here.

You may also want to see the Sourceforge Project Page.

inotify-tools consists of:

libinotifytools

This library provides a thin layer on top of the basic inotify interface. The primary use is to easily set up watches on files, potentially many files at once, and read events without having to deal with low-level I/O. There are also several utility functions for inotify-related string formatting.

Extensive documentation and some examples can be found here.

inotifywait

This command simply blocks for inotify events, making it appropriate for use in shell scripts. It can watch any set of files and directories, and can recursively watch entire directory trees.

inotifywait example 1

#!/bin/sh
# A slightly complex but actually useful example
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %f' \
 -e close_write /home/billy | while read date time file; do
    rsync /home/billy/${file} rsync://billy@example.com/backup/${file} && \
    echo "At ${time} on ${date}, file ${file} was backed up via rsync"
done

This may be the most efficient way to block for changes on files from a shell script.

If you don't specify which event you want to catch, all will be caught, and the event which occurred is output on stdout.

inotifywait example 2

#!/bin/sh

EVENT=$(inotifywait --format '%e' ~/file1)
[ $? != 0 ] && exit
[ "$EVENT" = "MODIFY" ] && echo 'file modified!'
[ "$EVENT" = "DELETE_SELF" ] && echo 'file deleted!'
# etc...

inotifywait will return true if an event you asked for is caught. If an event you didn't ask for is caught, it will return false; this generally occurs if you listen to a file on a particular partition and the partition is subsequently unmounted, or if you listen for a specific event and the file is deleted before that event occurs.

Read the inotifywait man page for more information.

inotifywatch

inotifywatch collects filesystem usage statistics and outputs counts of each inotify event.

inotifywatch example 1

In this example, I'm recursively watching ~/.beagle for 60 seconds, while beagled is running.

% inotifywatch -v -e access -e modify -t 60 -r ~/.beagle
Establishing watches...
Setting up watch(es) on /home/rohan/.beagle
OK, /home/rohan/.beagle is now being watched.
Total of 302 watches.
Finished establishing watches, now collecting statistics.
Will listen for events for 60 seconds.
total  access  modify  filename
1436   1074    362     /home/rohan/.beagle/Indexes/FileSystemIndex/PrimaryIndex/
1323   1053    270     /home/rohan/.beagle/Indexes/FileSystemIndex/SecondaryIndex/
303    116     187     /home/rohan/.beagle/Indexes/KMailIndex/PrimaryIndex/
261    74      187     /home/rohan/.beagle/TextCache/
206    0       206     /home/rohan/.beagle/Log/
42     0       42      /home/rohan/.beagle/Indexes/FileSystemIndex/Locks/
18     6       12      /home/rohan/.beagle/Indexes/FileSystemIndex/
12     0       12      /home/rohan/.beagle/Indexes/KMailIndex/Locks/
3      0       3       /home/rohan/.beagle/TextCache/54/
3      0       3       /home/rohan/.beagle/TextCache/bc/
3      0       3       /home/rohan/.beagle/TextCache/20/
3      0       3       /home/rohan/.beagle/TextCache/62/
2      2       0       /home/rohan/.beagle/Indexes/KMailIndex/SecondaryIndex/

Read the inotifywatch man page for more information.

Related Software

If inotify-tools doesn't quite do what you want, take a look at these programs.

pyinotify - high-level Python interface to inotify, makes it very easy to write Python based scripts for watching files.

IWatch - simple Perl script using inotify to watch files and directories, sending notifications of file changes by e-mail.

incron - inotify cron-like system; run commands when certain filesystem events occur.

logsend - daemon for e-mail notification of log file changes. Its inotify backend uses inotify-tools.

mswatch - keeps Unix mailboxes synchronized using inotify (or dnotify on older kernels).

inotail - a version of the tail utility which uses inotify to avoid polling for changes.

Something else - let me know if you know of any other useful inotify related programs.

SourceForge.net Logo Support This Project