inotifywait
TLDR
Watch a specific file for events, exiting after the first one
SYNOPSIS
inotifywait [options] file...
DESCRIPTION
inotifywait uses Linux's inotify API to efficiently watch files and directories for changes. It blocks until a filesystem event occurs, making it ideal for triggering actions on file changes.
Available events include:
- access - File read
- modify - File written
- create - File/directory created
- delete - File/directory deleted
- move - File moved
- attrib - Metadata changed
- close_write - File closed after writing
This is commonly used in scripts to rebuild projects, sync files, or trigger deployments when source files change.
PARAMETERS
-m, --monitor
Keep running, don't exit after first event-r, --recursive
Watch directories recursively-e, --event EVENT
Watch for specific events (access, modify, create, delete, etc.)-t, --timeout SECONDS
Exit after timeout with no events-q, --quiet
Suppress informational messages--exclude PATTERN
Exclude files matching regex pattern--format FMT
Custom output format-c, --csv
Output in CSV format
CAVEATS
Linux-only (uses inotify kernel subsystem). There are limits on the number of watches (configurable via /proc/sys/fs/inotify/maxuserwatches). Recursive watching creates a watch per directory. Not suitable for very large directory trees.
HISTORY
inotifywait is part of inotify-tools, created to provide user-space access to Linux's inotify API, which was introduced in kernel 2.6.13 (2005). It replaced the older dnotify mechanism.
SEE ALSO
inotifywatch(1), entr(1), fswatch(1), fatrace(1)


