Skip to content
rvoicilas edited this page Sep 13, 2010 · 45 revisions
inotify-tools

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(deprecated), Github project page, e-mail author, e-mail maintainer, libinotifytools API docs.

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

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.

Arch Linux

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

pacman -S inotify-tools

Sergej Pupykin is the Arch Linux package maintainer.

Everyone Else

Download inotify-tools source, then compile and install:

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

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

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

  • Fix: `—timefmt’ option to inotifywait doesn’t work (broken in 3.12)

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

  • Fix: inability to free memory allocated by inotifytools, and bogus memory
    leak check (causing `make check’ to fail on some systems).
  •  

  • Fix: spurious warning when the `—format’ option is given to inotifywait.

  •  
  • Fix: inotifywait fails to watch newly created directories when
    recursively watching a symlink to a directory.

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

  • Fixes a buffer overflow in the inotifytools_snprintf function.

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

  • Fix performance issues introduced in version 3.9.

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

  • Fix some bugs (including a crash and a memory leak) when watching an extremely large amount of files.

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

  • Remove some messages which were too verbose.

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

  • Add `—exclude’ and `—excludei’ options to inotifywait and inotifywatch and supporting function in libinotifytools. These allow events to be excluded if they match a given regular expression.
  • Probably fix some compile warnings to do with 64 bit pointers.
  • Add `extern "C"’ to headers when using C++.

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

  • Make inotifywait and inotifywatch correctly handle moving files into or out of watched directories.
  • Add a few functions to libinotifytools to facilitate the above.

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

  • Compilation fixed with versions of gcc earlier than 4.

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

  • Files can now be selectively excluded when watching directories recursively (thanks
    Ulrich Holeschak for the idea and initial implementation).
  • The list of files to watch or exclude can now be read in from a file (thanks Erik Nilsson for the idea).

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

  • Fixed inotify-tools on systems where the sys/inotify.h header is present but not implemented in glibc.
  • Added some automated tests to libinotifytools and fixed a few minor bugs uncovered by these tests.

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

  • -e option to inotifywait and inotifywatch fixed (it was broken in 3.0 and 3.1).

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

  • Compilation fixed for glibc 2.3 and older (it was broken in 3.0).

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

  • Added —timefmt option to inotifywait, allowing timestamps in output.
  • Now contains libinotifytools, a simple C library for developers who want to use inotify.

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

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

  • Fixed an issue which could cause the —format option to give incorrect output when an event occurs which would generate an empty string. Thanks to Dawid Gajownik for testing the 2.5 release.

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

  • Fixed an issue which could cause the —format option to fail when inotifywait is compiled with a hardened compiler (such as Fedora’s). Thanks to Tom Tromey and Dawid Gajownik for pointing this out.

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

  • inotifywait now has a really neat customizable printf-like —format option.
  • inotifywait can now output in CSV format. Whoa!
  • Newly created directories are now watched when the -r option is passed to inotifywait.
  • The default output format for inotifywait was improved and made more predictable (and hence easier to parse in scripts).
  • Slight documentation improvements.

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

  • A few compilation warnings were fixed.
  • Compilation errors were fixed on a few architectures including ARM (thanks Rob Walker) and MIPS.
  • Some error messages were rewritten to be more informative.

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

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.

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 elselet me know if you know of any other useful inotify related programs.

SourceForge.net Logo Support This Project

Clone this wiki locally