inotifywait: watch directories for file changes

Trigger actions the instant files are created, modified or deleted using inotifywait from inotify-tools.

LinuxinotifymonitoringeventsLow risk
Run inotifywait -m -r -e create,modify,delete DIR to print each change event as it happens, or loop over its output in a script to react to them.

01Command

Command
$ inotifywait -m -r --format '%w%f %e' -e create,modify,delete /var/www/uploads

02What it does

inotifywait is the front door to the kernel's inotify API: instead of polling with find or ls in a loop, the kernel wakes your process on the exact event. -m keeps monitoring after the first event (default is one-shot), -r recurses into subdirectories, -e filters which events you care about, and --format controls the output line so a while read loop can dispatch on it. Typical uses: auto-processing uploaded files, syncing changes, or running tests when code is saved.

03Risk

RiskLow risk
Requirementsinotify-tools package
!Warning: inotify watches are finite (see /proc/sys/fs/inotify/max_user_watches); watching huge trees recursively can exhaust them and silently miss events.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • inotifywait(1) — Arch Linux manual
    Arch Linux · technical · 2026-09-17
    Evidence: -m monitor continuously, -r recursive, -e selects events, --format customizes the output line
  • inotifywait(1) — Ubuntu manpage
    Canonical · technical · 2026-09-17
    Evidence: -m monitor continuously, -r recursive, -e selects events (create, modify, delete, move), --format customizes output

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions