talira

fsnotify

Cross-platform file system notifications for Go

open sourceBSD-3-Clausefree

fsnotify is a Go library that watches files and directories for changes and delivers create, write, remove, rename and chmod events on a channel. It uses each system's own interface: inotify on Linux, kqueue on BSD and macOS, ReadDirectoryChangesW on Windows and FEN on illumos. A watcher is added per directory, and the project recommends watching a file's parent directory rather than the file, since editors often replace files atomically. It needs Go 1.23 or newer.

Problems it solves

  • rerun something in my Go program when a config file changes
  • watch a directory for new files from Go on Linux, macOS and Windows
  • get notified in Go when a file is written or deleted

Features

  • Create, write, remove, rename and chmod events on a Go channel
  • inotify on Linux, kqueue on BSD and macOS, ReadDirectoryChangesW on Windows, FEN on illumos
  • One watcher for many paths, with an errors channel
  • Example commands in cmd/fsnotify

Limitations

  • Subdirectories aren't watched: you add a watch for each directory1
  • Doesn't work on NFS, SMB, FUSE, /proc or /sys, and there's no polling fallback yet1
  • No FSEvents backend on macOS yet, so Spotlight indexing can cause extra events1