← 返回命令列表

Linux command

watchexec 命令

文本

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

常用示例

Run a command

watchexec [command]

Watch specific directories

watchexec -w [src] -w [tests] [command]

Filter by file extensions

watchexec -e rs,toml [cargo build]

Restart a server

watchexec -r [./server]

Clear screen

watchexec -c [command]

Ignore specific paths

watchexec -i [node_modules] -i [*.log] [command]

Debounce with custom delay

watchexec -d [500] [command]

Wait for first change

watchexec --postpone [command]

说明

watchexec monitors filesystem paths and executes commands when changes are detected. It uses native file system notification APIs for efficient watching and supports gitignore-style filtering. The tool is commonly used for development workflows like auto-recompiling code, restarting servers, running tests, or regenerating documentation. It respects .gitignore and .ignore files by default. watchexec is written in Rust and provides consistent behavior across Linux, macOS, and Windows.

参数

-w, --watch _path_
Paths to watch (can be specified multiple times).
-e, --exts _extensions_
Filter by file extensions (comma-separated).
-f, --filter _pattern_
Gitignore-style patterns for files to include.
-i, --ignore _pattern_
Gitignore-style patterns for files to exclude.
-r, --restart
Restart the command if it's still running when changes occur.
-s, --signal _signal_
Send signal to stop command (e.g., SIGHUP, SIGKILL).
-c, --clear
Clear the screen before each command run.
-d, --debounce _ms_
Minimum milliseconds between command runs (default: 50).
-W, --watch-when-idle
Ignore changes while command is running.
--postpone
Wait for first change before running command.
--no-vcs-ignore
Don't use .gitignore files.
--no-default-ignore
Don't use built-in ignore patterns.
--poll _interval_
Use polling instead of native file system events.
-v, --verbose
Print debugging information.
-V, --version
Print version information.
-h, --help
Print help message.

FAQ

What is the watchexec command used for?

watchexec monitors filesystem paths and executes commands when changes are detected. It uses native file system notification APIs for efficient watching and supports gitignore-style filtering. The tool is commonly used for development workflows like auto-recompiling code, restarting servers, running tests, or regenerating documentation. It respects .gitignore and .ignore files by default. watchexec is written in Rust and provides consistent behavior across Linux, macOS, and Windows.

How do I run a basic watchexec example?

Run `watchexec [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -w, --watch _path_ do in watchexec?

Paths to watch (can be specified multiple times).