← 返回命令列表

Linux command

fswatch 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Watch directory

fswatch [/path/to/directory]

Watch and execute command

fswatch -o [/path/to/directory] | xargs -n1 -I{} [command]

Watch with recursive monitoring

fswatch -r [/path/to/directory]

Watch specific file types

fswatch --include ".*\\.txt$" --exclude ".*" [/path/to/directory]

Watch with one event per change

fswatch -1 [/path/to/directory]

Watch multiple paths

fswatch [/path/dir1] [/path/dir2]

Verbose output

fswatch -t [/path/to/directory]

Watch with latency

fswatch -l [2] [/path/to/directory]

说明

fswatch is a cross-platform file change monitor that detects filesystem changes and outputs affected paths. It uses native platform APIs (inotify on Linux, FSEvents on macOS, kqueue on BSD) for efficient monitoring. The tool outputs changed file paths to stdout, which can be piped to other commands for automated workflows like rebuilding projects, running tests, or reloading services. It supports recursive monitoring and filtering by file patterns. fswatch is useful for development workflows, build automation, backup triggers, and any scenario where actions should be triggered by file modifications.

参数

-o, --one-per-batch
Print single event per batch (for counting).
-r, --recursive
Recurse into subdirectories.
-t, --timestamp
Print timestamps with events.
-l _seconds_, --latency= _seconds_
Set latency (debounce period).
-1, --one-event
Exit after first event.
-0, --print0
Separate paths with NUL character.
--event _type_
Filter by event type.
--include _regex_
Include only matching files.
--exclude _regex_
Exclude matching files.
-m _monitor_, --monitor= _monitor_
Use specific monitor backend.
-v, --verbose
Verbose output.
-n, --numeric
Print numeric event codes.

FAQ

What is the fswatch command used for?

fswatch is a cross-platform file change monitor that detects filesystem changes and outputs affected paths. It uses native platform APIs (inotify on Linux, FSEvents on macOS, kqueue on BSD) for efficient monitoring. The tool outputs changed file paths to stdout, which can be piped to other commands for automated workflows like rebuilding projects, running tests, or reloading services. It supports recursive monitoring and filtering by file patterns. fswatch is useful for development workflows, build automation, backup triggers, and any scenario where actions should be triggered by file modifications.

How do I run a basic fswatch example?

Run `fswatch [/path/to/directory]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --one-per-batch do in fswatch?

Print single event per batch (for counting).