LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

inotifywait

uses Linux's inotify API to efficiently watch files and directories for changes

TLDR

Watch a specific file for events, exiting after the first one
$ inotifywait [path/to/file]
copy
Continuously watch a file for events
$ inotifywait -m [path/to/file]
copy
Watch a directory recursively for events
$ inotifywait -m -r [path/to/directory]
copy
Watch a directory excluding files matching regex
$ inotifywait -m -r --exclude "[regex]" [path/to/directory]
copy
Watch with a timeout of 30 seconds
$ inotifywait -m -t 30 [path/to/file]
copy
Watch only for specific events (modify)
$ inotifywait -e modify [path/to/file]
copy
Watch quietly (no status messages)
$ inotifywait -q [path/to/file]
copy
Run a command when a file is accessed
$ inotifywait -e access [path/to/file] && [command]
copy

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 writingThis 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

INSTALL

sudo apt install inotify-tools
copy
sudo dnf install inotify-tools
copy
sudo pacman -S inotify-tools
copy
sudo apk add inotify-tools
copy
sudo zypper install inotify-tools
copy
brew install inotify-tools
copy
nix profile install nixpkgs#inotify-tools
copy

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

entr(1), fswatch(1), fatrace(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid