Linux command
watch 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Execute a command every 2 seconds
watch [command]
Execute a command
watch -n [5] [command]
Highlight differences
watch -d [command]
Exit when output changes
watch -g [command]
Hide the header
watch -t [command]
Beep on command error
watch -b [command]
Preserve ANSI colors
watch -c [ls --color=always]
Exit on command error
watch -e [command]
说明
watch executes a command repeatedly, displaying output in full-screen mode. This allows monitoring of changing data such as disk usage, running processes, or log files without manually re-running commands. By default, the command runs every 2 seconds. The header displays the interval, command, and current time. Use -d to highlight what changed between updates—useful for spotting modifications in large output. The command is passed to sh -c, so shell features like pipes and redirects work but may require quoting. Non-printing characters are stripped; use cat -v in the pipeline to see them.
参数
- -n, --interval _SECS_
- Update interval in seconds (default: 2, min: 0.1, max: 2678400)
- -d, --differences =_permanent_
- Highlight differences; permanent shows all changes since start
- -g, --chgexit
- Exit when output changes
- -e, --errexit
- Freeze on error and exit after key press
- -b, --beep
- Beep on non-zero exit code
- -c, --color
- Interpret ANSI color sequences
- -C, --no-color
- Do not interpret ANSI color sequences
- -t, --no-title
- Hide header (interval, command, time)
- -w, --no-wrap
- Disable line wrapping
- -p, --precise
- Run command at precise intervals from start time
- -f, --follow
- Scroll output like tail -f instead of clearing
- -q, --equexit _CYCLES_
- Exit when output does not change for the given number of cycles
- -x, --exec
- Pass command to exec instead of sh -c
- -h, --help
- Show help
- -v, --version
- Show version
FAQ
What is the watch command used for?
watch executes a command repeatedly, displaying output in full-screen mode. This allows monitoring of changing data such as disk usage, running processes, or log files without manually re-running commands. By default, the command runs every 2 seconds. The header displays the interval, command, and current time. Use -d to highlight what changed between updates—useful for spotting modifications in large output. The command is passed to sh -c, so shell features like pipes and redirects work but may require quoting. Non-printing characters are stripped; use cat -v in the pipeline to see them.
How do I run a basic watch example?
Run `watch [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --interval _SECS_ do in watch?
Update interval in seconds (default: 2, min: 0.1, max: 2678400)