Skip to content
Ilja edited this page May 7, 2024 · 46 revisions

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.

Quick links: download, Github project page, e-mail author, e-mail maintainer.

  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!

Mageia

inotify-tools is available in the Mageia core repository. You can install it with:

urpmi inotify-tools

OpenSUSE

inotify-tools is available through the distribution’s repositories. Just do:

zypper in inotify-tools

Fedora

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

dnf install inotify-tools

Adel Gadllah is the Fedora package maintainer.

CentOS/RHEL 7

inotify-tools is available through the EPEL repository. Install EPEL :

yum install -y epel-release && yum update

Then install package:

yum install inotify-tools

In case of CentOS-7

yum --enablerepo=epel install inotify-tools

v3.14-8.el7.×86_64 as of 4-18-2018

Gentoo

inotify-tools is available in Gentoo’s official portage tree. You can simply run:

emerge inotify-tools

to install it

Lars Wendler 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

Joao Eriberto Mota Filho is the Debian package maintainer.

Void Linux

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

xbps-install inotify-tools

Enno Boland is the Void Linux package maintainer.

Alpine Linux

inotify-tools is available in the Alpine Linux main repository. You can install it with:

apk add inotify-tools

FreeBSD

inotify-tools is available as a port and package. It can be installed with the following command:

pkg install inotify-tools

or

cd /usr/ports/sysutils/inotify-tools/ && make install clean

Yuri is the FreeBSD 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 (@biow0lf) 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.

NixOS Linux

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

nix-env -i inotify-tools

Github users marcweber and pSub are the NixOS package maintainers.

Guix System

A package is available in the main repo and it can be installed with the following command:

guix install inotify-tools

Source Mage GNU/Linux

inotify-tools can be installed with the following command:

cast inotify-tools

Package maintained by the Source Mage team.

ROSA Linux

inotify-tools can be installed from the Contrib repository by running:

urpmi inotify-tools

Denis Silakov is the ROSA Linux package maintainer.

Slackware

comes with inotify-tools by default

PLD Linux

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

poldek -u inotify-tools

Everyone Else

Download inotify-tools source from Github project page then compile and install:

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

30 January 2020: Release notes moved to releases

7 March 2010: inotify-tools 3.14 released. Most of the changes are patches from our users or package maintainers. Thank you!

23 November 2009: inotify-tools moved to github

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.

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 30 January 2020 the project is maintained by Eric Curtin (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, open an issue or pull request. General queries about development with inotify are also welcome here.

You may also want to see the Github 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.

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 (thanks to Nick Lothian)

#!/bin/sh

cwd=$(pwd)

inotifywait -mr \
  --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
  -e close_write /tmp/test |
while read -r date time dir file; do
       changed_abs=${dir}${file}
       changed_rel=${changed_abs#"$cwd"/}

       rsync --progress --relative -vrae 'ssh -p 22' "$changed_rel" \
           [email protected]:/backup/root/dir && \
       echo "At ${time} on ${date}, file $changed_abs was backed up via rsync" >&2
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) || exit
[ "$event" = "MODIFY" ] && echo 'file modified!' >&2
[ "$event" = "DELETE_SELF" ] && echo 'file deleted!' >&2
# 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.

notitools – some useful inotify tools.

adhocify – can launch scripts upon inotify events. requires no config files.