watch
プロセスとシステム
書き方
watch -n <seconds> "<command>"同じコマンドを数秒ごとに走らせ直し、画面を描き替えます。パイプや `*` を含む命令は必ず引用符で囲みます(でないとシェルが watch 自身に一度だけ適用します)。macOS には既定で入っていません。
よく使うオプション
| オプション | 意味 |
|---|---|
| -n 5 | Interval in seconds; the default is 2. |
| -d | Highlight what changed since the last run. |
| -t | Drop the header line. |
| -g | Exit as soon as the output changes. |
| -x | Run the command directly instead of through a shell. |
例
watch -n 5 "kubectl get pods"Quote it, or the shell hands watch only the first word.
watch -d free -hWatch memory move, with the changes highlighted.
何が動いていて何が資源を食っているかを見ます。止める前に何なのかを確かめるのが順番です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. watch は何をしますか。
同じコマンドを数秒ごとに走らせ直し、画面を描き替えます。パイプや `*` を含む命令は必ず引用符で囲みます(でないとシェルが watch 自身に一度だけ適用します)。macOS には既定で入っていません。
Q. どう打ちますか。
watch -n <seconds> "<command>" — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは5個です。全部は man watch にあります。このコマンドはプロセスとシステムの仲間です。
関連するコマンド
man ページ: man watch