fswatch(7)
π NAME π
Okay so fswatch(7) β from the Miscellaneous Information Manual β is literally the page for asking for a notification when the contents of the specified files or directory hierarchies are modified. π
Real talk though: this man page is kept for reference but it is not to be considered an authoritative or complete source of information. Please, consult the official Info documentation shipped with . π«Ά
πΈ SYNOPSIS πΈ
fswatch (option)* path+
Translation: you run fswatch, toss in zero or more options, then hand it one or more paths. Slay. β¨
π¦ DESCRIPTION π¦
The fswatch command receives notifications when the contents of the specified files or directories are modified. fswatch implements seven kind of monitors β yes, seven kind, thatβs what the page says, weβre not editing the vibe:
- A monitor based on the File System Events API of Apple macOS.
- A monitor based on
kqueue, an event notification interface introduced in FreeBSD 4.1 and supported on most *BSD systems (including macOS). - A monitor based on the File Events Notification API of the Solaris kernel and its derivatives.
- A monitor based on
inotify, a Linux kernel subsystem that reports file system changes to applications. - A monitor based on
fanotify, a Linux kernel subsystem that can report file system changes with optional process attribution. - A monitor based on the ReadDirectoryChangesW Microsoft Windows API. Native MinGW-w64 builds are the recommended Windows target; Cygwin builds are kept for compatibility when the Cygwin path conversion API is available.
- A monitor which periodically stats the file system, saves file modification times in memory and manually calculates changes.
fswatch writes a record for each event it receives containing:
- The timestamp when the event was received (optionally).
- The path affected by the current event.
- A space-separated list of event types (see βEVENT TYPESβ).
By default, fswatch enters an infinite loop and never returns. When it receives a SIGABRT, SIGINT or SIGTERM signal, fswatch closes the notification streams and exits gracefully returning 0 to the calling process. (Unless running in [-1, --one-event] mode, in which case it sets its return code according to the signal it received, as usual.)
β¨ The following options are available β¨
-0,--print0β Use the ASCII NUL character (\0) as line separator. Since file names can potentially contain any character but NUL, this option assures that the output offswatchcan be safely parsed using NUL as delimiter, such as usingxargs -0and the shell builtinread -d ''.-1,--one-eventβ Exitfswatchafter the first set of events is received.--batch-markermarker β Print a marker at the end of every batch. An optional marker marker can be specified to override its default valueNoOp.--eventname β Filter event with the specified name. This option can be used multiple times, one for each event name that must be included in the output.-e,--excluderegexp β Exclude paths matching regexp. Multiple exclude filters can be specified using this option multiple times. See βFILTERING PATHSβ for further information.-E,--extendedβ Use extended regular expressions.--filter-modemode β Set the path filter evaluation mode. mode can belegacyorconjunctive. See βFILTERING PATHSβ for further information.-f,--format-timeformat β Print the event time using the specified format. Supported formats are specified bystrftime(3).--formatformat β Use the specified event record format. The format string supportspath,flag,timestamp,correlation, and monitor-specific metadata directives includingfanotifyprocess attribution.-h,--helpβ Show the help message.-i,--includeregexp β Include paths matching regexp. Multiple include filters can be specified using this option multiple times. See βFILTERING PATHSβ for further information.-I,--insensitiveβ Use case insensitive regular expressions.-l,--latencylatency β Set the latency in seconds. The latency is a double value greater than0.1. Smaller values are currently not allowed in order not to compromise the performance of the system. The default latency is1second.-L,--follow-linksβ Follow symbolic links.-M,--list-monitorsβ List the available monitors.-m,--monitorname β Uses the monitor specified by name. The list of currently available monitors can be obtained using the-hoption.--no-deferβ Sets thekFSEventStreamCreateFlagNoDeferflag on the macOS FSEvents monitor, which makes the monitor more responsive. This flag is more appropriate for sessions, while the default behaviour is more appropriate for background, daemon or batch processing apps.-n,--numericβ Print the numeric value of the event flag, instead of the array of symbolic names. The numeric value of the event flags are system-specific and may vary across different versions of macOS. As a consequence, the use of numeric values is discouraged.-o,--one-per-batchβ Print a single message with the number of change events.--pruneregexp β Do not descend into directories matching regexp during recursive traversal. This option may be specified multiple times. See βFILTERING PATHSβ for further information.-r,--recursiveβ Watch subdirectories recursively. This option may not be supported on all systems.-t,--timestampβ Print the event timestamp.-u,--utc-timeβ Print the event time in UTC format. When this option is not specified, the time is printed using the system local time, as defined bylocaltime(3).-v,--verboseβ Print verbose output.--versionβ Print the version offswatchand exits.-x,--event-flagsβ Prints the event flags.--event-flag-separatorseparator β Print event flags using the specified separator.
π MONITORS π
fswatch acts as a front-end to system-specific monitors. Currently, the available monitors are:
- The FSEvents monitor, a monitor based on the File System Events API of Apple macOS.
- The kqueue monitor, a monitor based on
kqueue, an event notification interface introduced in FreeBSD 4.1 and supported on most *BSD systems (including macOS). - The inotify monitor, a Linux kernel subsystem that reports file system changes to applications.
- The fanotify monitor, a Linux kernel subsystem that can report file system changes with optional process attribution.
- The poll monitor, a monitor which periodically stats the file system, saves file modification times in memory and manually calculates file system changes, which can work on any operating system where
stat(2)can be used.
Each monitor has its own strengths, weakness and peculiarities. Although fswatch strives to provide a uniform experience no matter which monitor is used, it is still important for users to know which monitor they are using and to be aware of existing bugs, limitations, corner cases or pathological behaviour. π
π The FSEvents Monitor π
The FSEvents monitor, available only on Apple macOS, has no known limitations and scales very well with the number of files being observed. In fact, I observed no performance degradation when testing fswatch observing changes on a filesystem of 500 GB over long periods of time. On macOS, this is the default monitor. π
π§ The kqueue Monitor π§
The kqueue monitor, available on any *BSD system featuring kqueue, requires a file descriptor to be opened for every file being watched. As a result, this monitor scales badly with the number of files being observed and may begin to misbehave as soon as the fswatch process runs out of file descriptors. In this case, fswatch dumps one error on standard error for every file that cannot be opened. Beware that on some systems the maximum number of file descriptors that can be opened by a process is set to a very low value (values as low as 256 are not uncommon), even if the operating system may allow a much larger value.
If you are running out of file descriptors when using this monitor and you cannot reduce the number of observed items, either:
- Consider raising the number of maximum open file descriptors (check your OS documentation).
- Consider using another monitor.
π The inotify Monitor π
The inotify monitor, available on Linux since kernel 2.6.13, may suffer a queue overflow if events are generated faster than they are read from the queue. In any case, the application is guaranteed to receive an overflow notification which can be handled to gracefully recover. fswatch currently throws an exception if a queue overflow occurs. Future versions will handle the overflow by emitting proper notifications. However, the odds of observing a queue overflow on a default configured mainstream GNU/Linux distribution is very low.
The inotify API provides no information about the user or process that triggered an event, so applications cannot easily distinguish events they trigger themselves from events triggered by other processes. Inotify reports only events triggered through the filesystem API, so it does not catch remote events that occur on network filesystems. Furthermore, pseudo-filesystems such as /proc, /sys, and /dev/pts are not monitorable with inotify.
The inotify API does not report file accesses or modifications that may occur because of mmap(2), msync(2), and munmap(2). It identifies affected files by filename, but by the time the application processes the event, the filename may already have been deleted or renamed. Events are identified via watch descriptors, so applications must cache a mapping, if one is needed, between watch descriptors and pathnames. Be aware that directory renamings may affect multiple cached pathnames.
The inotify API sends events for the direct child elements of a watched directory and it scales pretty well with the number of watched items. For this reason, depending on the number of files to watch, it may sometimes be preferable to watch a common parent directory and filter received events rather than adding a huge number of file watches. Inotify monitoring of directories is not recursive, so additional watches must be created for subdirectories. That can take a significant amount of time for large directory trees. π¦
Honestly bestie, the moment you add a watch for a brand-new subdirectory, there might already be new files and subdirectories chilling inside it β the tree moves faster than you do π So if you're monitoring an entire directory subtree and a new subdirectory gets created in it (or an existing one gets renamed into it), you're gonna want to scan the contents of that subdirectory immediately after adding the watch, and, if desired, recursively add watches for any subdirectories it contains. Do it. Don't skip this step.
Also, heads up: the event queue can overflow. When that happens, events are lost. No cap. Robust applications should handle the possibility of lost events gracefully β like, for example, it may be necessary to rebuild part or all of the application cache. Build for the chaos, bestie π«Ά
And one more vibe-killer: if a filesystem is mounted on top of a monitored directory, no event is generated, and no events are generated for objects immediately under the new mount point. If the filesystem is subsequently unmounted, events will subsequently be generated for the directory and the objects it contains. It's giving "out of sight, out of mind" π
πΈ The fanotify Monitor πΈ
The fanotify monitor β available on Linux when the build system detects the required fanotify headers and symbols β uses file-handle based fanotify events. It is not the default Linux monitor, so you have to select it explicitly, like:
$ fswatch -m fanotify_monitor path ...
The fanotify monitor is useful when Linux-specific process attribution is required. The custom format directive %K prints the identifier kind, such as pid or tid, and prints the reported process or thread identifier. The monitor property accepts pid or tid. The fanotify.report-pidfd property requests pidfd reporting when supported by the build headers and kernel; the pidfd is exposed through the library event metadata only while the callback is executing. Blink and it's gone π
Fanotify reports only events triggered through the filesystem API, so it does not catch remote events that occur on network filesystems. It also does not report accesses or modifications that may occur because of mmap(2), msync(2), and munmap(2). Directory events are created only if the directory itself is opened, read, and closed β so adding, removing, or changing children of a marked directory does not create events for the monitored directory itself. And fanotify monitoring of directories is not recursive: monitoring subdirectories requires additional marks, and using FAN_CREATE to detect them is racy because events may be lost before a new mark is added. Monitoring mounts or entire filesystems avoids that race. The event queue can also overflow, in which case events are lost. Classic π
The fanotify.unlimited-queue and fanotify.unlimited-marks properties request FAN_UNLIMITED_QUEUE and FAN_UNLIMITED_MARKS, respectively. These properties are opt-in because they require matching build headers and the capability expected by the running kernel β typically CAP_SYS_ADMIN β and fanotify initialization fails if the process lacks it. So yeah, permission check first, vibes second π
Fanotify support depends on kernel, C library, filesystem, and permission support for the requested mode. Some filesystems do not support file handles, and some fanotify modes require additional privileges. Use the inotify monitor when broad Linux compatibility is more important than process attribution. iykyk.
Fanotify directory marks are not equivalent to macOS FSEvents recursive tree watches. With ordinary directory marks, FAN_EVENT_ON_CHILD reports events for immediate children only β not grandchildren or deeper descendants. Recursive fanotify monitoring therefore still marks subdirectories explicitly. Avoiding recursive mark expansion requires fanotify mount or filesystem marks, which have broader scope and different permission constraints. Main character energy, honestly π
π The Poll Monitor π
The poll monitor was added as a fallback mechanism in the cases where no other monitor could be used, including:
- Operating system without any sort of file events API.
- Situations where the limitations of the available monitors cannot be overcome (i.e.: observing a number of files greater than the available file descriptors on a system using the kqueue monitor).
The poll monitor, available on any platform, only relies on available CPU and memory to perform its task (besides the stat(2) function). The performance of this monitor degrades linearly with the number of files being watched. The authors' experience indicates that fswatch requires approximately 150 MB or RAM memory to observe a hierarchy of 500.000 files with a minimum path length of 32 characters. A common bottleneck of the poll monitor is disk access, since stat()-ing a great number of files may take a huge amount of time. In this case, the latency should be set to a sufficiently large value in order to reduce the performance degradation that may result from frequent disk access. tl;dr: it's the fallback for a reason, but it slays in a pinch π
π How to Choose a Monitor π
fswatch already chooses the "best" monitor for your platform if you do not specify any. However, a specific monitor may be better suited to specific use cases. Please, read the "MONITORS" section to get a description of all the available monitors and their limitations. Do your homework bestie π
Usage recommendations are as follows:
- On macOS, use only the FSEvents monitor (which is the default behaviour).
- On Linux, use the inotify monitor (which is the default behaviour).
- On Linux, use the fanotify monitor only when its Linux-specific process attribution or fanotify semantics are required.
- If the number of files to observe is sufficiently small, use the kqueue monitor. Beware that on some systems the maximum number of file descriptors that can be opened by a process is set to a very low value (values as low as 256 are not uncommon), even if the operating system may allow a much larger value. In this case, check your OS documentation to raise this limit on either a per process or a system-wide basis.
- If feasible, watch directories instead of watching files. Properly crafting the receiving side of the events to deal with directories may sensibly reduce the monitor resource consumption. Work smarter, not harder β¨
- If none of the above applies, use the poll monitor. The authors' experience indicates that fswatch requires approximately 150 MB or RAM memory to observe a hierarchy of 500.000 files with a minimum path length of 32 characters. A common bottleneck of the poll monitor is disk access, since
stat()-ing a great number of files may take a huge amount of time. In this case, the latency should be set to a sufficiently large value in order to reduce the performance degradation that may result from frequent disk access.
π FILTERING PATHS π
Received events can be filtered by path using regular expressions. Regular expressions can be used to include or exclude matching paths. Super useful, honestly.
Explicit command-line root paths remain eligible for monitor setup even when an output filter would reject the root path itself. fswatch supports two path filter evaluation modes: 'legacy' and 'conjunctive'.
The default 'legacy' mode preserves historical behavior. The user can specify multiple filter expressions in any order and filters are processed this way:
- If a path matches an including filter, the path is accepted no matter any other filter.
- If a path matches an excluding filter, the path is rejected.
- If a path matches no filters, the path is accepted.
Said another way:
- All paths are accepted by default, unless an exclusion filter says otherwise.
- Inclusion filters may override any other exclusion filter.
- The order in the definition of filters in the command line has no effect.
The 'conjunctive' mode is enabled with --filter-mode=conjunctive. It treats inclusion filters as the candidate set and exclusion filters as subtractions from that set:
- If no inclusion filters are specified, all paths are candidates.
- If at least one inclusion filter is specified, a path must match an inclusion filter to be a candidate.
- Any matching exclusion filter rejects the path.
Said another way, conjunctive mode accepts paths matching this expression:
(no includes OR matches include) AND NOT matches exclude
For example, the following command reports changes to C source files except editor lock files:
$ fswatch --filter-mode=conjunctive -i '\.c$' -e '/lock-[^/]+.c$'.
π¦ Pruning Recursive Traversal π¦
The --prune regexp option defines regular expressions that stop recursive traversal from descending into matching directories. This is different from --exclude: excluded paths are filtered from reported events, while pruned directories and their descendants are skipped during library-side recursive traversal. Different tools for different jobs, bestie π
Pruning only affects monitors that perform this traversal in fswatch. Native recursive backends may accept --prune, but may not be able to prevent the operating system from traversing matching subtrees in the same way. Rude, but okay π
Prune expressions use the same case-sensitivity and extended-regular-expression settings as normal path filters.
Pruning is applied only to non-root directories. A command-line root path remains eligible for monitoring even if it matches a prune expression. Roots stay untouched, periodt.
For example, the following command recursively watches /home/me without descending into hidden directories:
$ fswatch -r --prune '/\.[^/]+$' /home/me
Other options govern how regular expressions are interpreted:
- Regular expressions can be extended if option
-Eis specified. - Regular expressions can be case insensitive if option
-Iis specified.
β¨ EVENT TYPES β¨
Okay bestie, so event flags are literally the little labels that tell you what kind of change happened to a file system object. Some of them map super directly to normal file system operations (create, delete, update, etc. β you know the drill), some are the rarer ones (attribute changes, hi π), and some are monitor- and platform-specific. No cap.
Right now, fswatch maps monitor-specific event flags onto 'global' event flags, which act like a sort of 'greatest common denominator' of all the monitor flags available to you. π
Here's the full global squad:
NoOpβ the idle event, optionally issued when literally no changes were detected. It's giving "nothing to report but I'm still here." π¦PlatformSpecificβ this event maps a platform-specific event that has no corresponding flag. Very "iykyk" energy.Createdβ the object has been created. New file just dropped. β¨Updatedβ the object has been updated. What kind of update? Monitor-dependent, babe. Don't ask me, ask the monitor.Removedβ the object has been removed. Gone. πRenamedβ the object has been renamed. Same vibe, new name.OwnerModifiedβ the object's owner has changed.AttributeModifiedβ an object's attribute has changed.MovedFromβ the object has moved from this location to a new location of the same file system.MovedToβ the object has moved from another location in the same file system into this location.IsFileβ the object is a regular file.IsDirβ the object is a directory.IsSymLinkβ the object is a symbolic link.Linkβ the object link count has changed.Overflowβ the monitor has overflowed. π Too much happened at once, bestie.
πΈ EXAMPLES πΈ
π Basic Usage
So the fswatch syntax is literally this:
$ fswatch [options] [paths] ...
Then fswatch just outputs change events to standard output. By default, only the affected file name gets printed β minimal, mysterious, main character energy. But there are so many options for formatting the event record, including:
- The possibility of adding the event timestamp. β°
- The possibility of adding the event mask in both textual and numerical form.
The following command listens for changes in the current directory, and events are delivered every 5 seconds:
$ fswatch -l 5 .
And this one listens for changes in the current user home directory and /var/log:
$ fswatch ~ /var/log
π«Ά Piping fswatch Output to Another Process
Very often you don't just wanna receive an event β you wanna react to it. The simplest way to do that is piping fswatch output to another process. But here's the tea: in Unix and Unix-like file systems, file names may potentially contain any character except NUL (\0) and the path separator (/). So fswatch has a specific mode of operation for when its output must be piped to another process. When the [-0] option is used, fswatch uses the NUL character as the record separator, which lets any other character show up in a path. π
This matters because lots of commands and shell builtins (like read) split words and lines by default using the characters in $IFS β and that by default contains characters which may be present (although rarely) in a file name. Result? A wrong event path being received and processed. The disrespect. π
Probably the simplest way to pipe fswatch to another program so you can respond to an event is using xargs:
$ fswatch -0 [opts] [paths] | xargs -0 -n 1 -I {} [command]
fswatch -0will split records using the NUL character.xargs -0will split records using the NUL character. This is required to correctly match impedance withfswatch.xargs -n 1will invokecommandevery record. If you want to do it every x records, then usexargs -n x.xargs -I {}will substitute occurrences of{}incommandwith the parsed argument. If the command you're running doesn't need the event path name, just delete this option. If you prefer using another replacement string, substitute{}with yours.
β οΈ Heads up on BSD-derived systems, including macOS: the systemxargsimplementation may limit the size of replacement strings used by-I. If commands fail when processing long path names, consider using a different consumer that readsfswatch's NUL-separated records directly, or install GNU findutils and usegxargsinstead ofxargs. Not me warning you twice. π
π Bubbling Events
An often requested feature is being able to receive a single event "per batch" instead of receiving multiple events. That use case is implemented by the [-o, --one-per-batch] option, which tells fswatch to dump a record containing the number of received events, without any other detail:
$ fswatch -or /path/to/watch
1
10
[...]
This is useful if, for example, you want to respond to change events in a way which is (or can easily be) path-independent β because you're not receiving any event detail β and you prefer to "bubble" events together to reduce the overhead of the command being executed. A typical case is a directory synchronisation job whenever some files change. Obsessed with the efficiency honestly. β¨
β Receiving a Single Event
Another requested feature is the possibility of receiving a single event and then exiting. This is most useful when existing scripts processing events include the restart logic of fswatch. This use case is implemented by the [-1, --one-event] option:
$ fswatch -1 /path/to/watch
/path/to/watch
π Compatibility With fswatch 0.x π
The previous major version of fswatch (v. 0.x) let users run a command whenever a set of changes was detected, with this syntax:
$ fswatch path program
Starting with fswatch v. 1.x, this behaviour is no longer supported. The rationale behind this decision includes:
- The old version only allows watching one path.
- The command to execute was passed as last argument, alongside the path to watch, making it difficult to extend the program functionality to add multiple path support.
- The old version forks and executes
/bin/bash, which is neither portable, nor guaranteed to succeed, nor desirable by users of other shells. - No information about the change events is passed to the forked process.
To solve the aforementioned issues and keep fswatch consistent with common UNIX practices, the behaviour has changed: fswatch now prints event records to the standard output that users can process further by piping the output of fswatch to other programs.
To fully support the old use, the [-o, --one-per-batch] option was added in v. 1.3.3. When specified, fswatch will only dump 1 event to standard output, which can be used to trigger another program:
$ fswatch -o path | xargs -n1 program
In this case, program will receive the number of change events as first argument. If no argument should be passed to program, then the following command could be used:
$ fswatch -o path | xargs -n1 -I{} program
π₯ EXIT STATUS π₯
fswatch may exit with one of the following exit statuses β look at all these little guys:
FSW_OK 0
FSW_ERR_UNKNOWN_ERROR (1 << 0)
FSW_ERR_SESSION_UNKNOWN (1 << 1)
FSW_ERR_MONITOR_ALREADY_EXISTS (1 << 2)
FSW_ERR_MEMORY (1 << 3)
FSW_ERR_UNKNOWN_MONITOR_TYPE (1 << 4)
FSW_ERR_CALLBACK_NOT_SET (1 << 5)
FSW_ERR_PATHS_NOT_SET (1 << 6)
FSW_ERR_UNKNOWN_MONITOR (1 << 7)
FSW_ERR_MISSING_CONTEXT (1 << 8)
FSW_ERR_INVALID_PATH (1 << 9)
FSW_ERR_INVALID_CALLBACK (1 << 10)
FSW_ERR_INVALID_LATENCY (1 << 11)
FSW_ERR_INVALID_REGEX (1 << 12)
FSW_ERR_MONITOR_ALREADY_RUNNING (1 << 13)
FSW_ERR_STALE_MONITOR_THREAD (1 << 14)
FSW_ERR_THREAD_FAULT (1 << 15)
FSW_ERR_UNSUPPORTED_OPERATION (1 << 16)
FSW_ERR_UNKNOWN_VALUE (1 << 17)
π¦ DIAGNOSTICS π¦
fswatch exits 0 on success, and >0 if an error occurs. Simple as that, bestie. β¨
π COMPATIBILITY π
fswatch can be built on any system supporting at least one of the available monitors. Iconic behaviour, honestly.
π BUGS π
See https://github.com/emcrisostomo/fswatch/issues for open issues or to create a new one. Your girl loves a good issue tracker.
Bugs can also be submitted to enrico.m.crisostomo@gmail.com. π§
And that's the whole page, bestie β you ate. π
This one's fswatch(7) from the pc linux-gnu corner of the universe, dated August 05, 2026, so go forth and watch those file systems. Mwah. π«Άππ
π¦ where this page comes from
- arch rolling: fswatch 1.22.0-2 Β· GPL-3.0-or-later OR Apache-2.0
- Copyright (c) 2013-2026 Enrico M. Crisostomo <enrico.m.crisostomo@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms