Linux command
inotifywait 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Watch
inotifywait [path/to/file]
Continuously watch
inotifywait -m [path/to/file]
Example
inotifywait -m -r [path/to/directory]
Example
inotifywait -m -r --exclude "[regex]" [path/to/directory]
Example
inotifywait -m -t 30 [path/to/file]
Example
inotifywait -e modify [path/to/file]
Example
inotifywait -q [path/to/file]
Example
inotifywait -e access [path/to/file] && [command]
说明
inotifywait uses Linux's inotify API to efficiently watch files and directories for changes. It blocks until a filesystem event occurs, making it ideal for triggering actions on file changes. Available events include: - access - File read - modify - File written - create - File/directory created - delete - File/directory deleted - move - File moved - attrib - Metadata changed - close_write - File closed after writing This is commonly used in scripts to rebuild projects, sync files, or trigger deployments when source files change.
参数
- -m, --monitor
- Keep running, don't exit after first event
- -r, --recursive
- Watch directories recursively
- -e, --event _EVENT_
- Watch for specific events (access, modify, create, delete, etc.)
- -t, --timeout _SECONDS_
- Exit after timeout with no events
- -q, --quiet
- Suppress informational messages
- --exclude _PATTERN_
- Exclude files matching regex pattern
- --format _FMT_
- Custom output format
- -c, --csv
- Output in CSV format
FAQ
What is the inotifywait command used for?
inotifywait uses Linux's inotify API to efficiently watch files and directories for changes. It blocks until a filesystem event occurs, making it ideal for triggering actions on file changes. Available events include: - access - File read - modify - File written - create - File/directory created - delete - File/directory deleted - move - File moved - attrib - Metadata changed - close_write - File closed after writing This is commonly used in scripts to rebuild projects, sync files, or trigger deployments when source files change.
How do I run a basic inotifywait example?
Run `inotifywait [path/to/file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -m, --monitor do in inotifywait?
Keep running, don't exit after first event