Debian Codegraph @

man/watch.1

raw
1 .\"
2 .\" Copyright (c) 2023 Roman Žilka <[email protected]>
3 .\" Copyright (c) 2009-2025 Craig Small <[email protected]>
4 .\" Copyright (c) 2018-2023 Jim Warner <[email protected]>
5 .\" Copyright (c) 2011-2012 Sami Kerola <[email protected]>
6 .\" Copyright (c) 2003 Albert Cahalan
7 .\"
8 .\" This program is free software; you can redistribute it and/or modify
9 .\" it under the terms of the GNU General Public License as published by
10 .\" the Free Software Foundation; either version 2 of the License, or
11 .\" (at your option) any later version.
12 .\"
13 .\"
14 .TH WATCH 1 2025-04-16 procps-ng
15 .SH NAME
16 watch \- execute a program periodically, showing output fullscreen
17 .SH SYNOPSIS
18 .B watch
19 .RI [ option " .\|.\|.\&]"
20 .I command
21 .SH DESCRIPTION
22 .B watch
23 runs
24 .I command
25 repeatedly, displaying its output and errors (the first screenful). This
26 allows you to watch the program output change over time. By default,
27 \fIcommand\fR is run every 2 seconds and \fBwatch\fR will run until interrupted.
28 A header informs of the start and running time of \fIcommand\fR as well as its
29 exit code.
30 .SH OPTIONS
31 .TP
32 \fB\-b\fR, \fB\-\-beep\fR
33 Beep if \fIcommand\fR has a non-zero exit.
34 .TP
35 \fB\-c\fR, \fB\-\-color\fR
36 Interpret ANSI color and style sequences.
37 .TP
38 \fB\-C\fR, \fB\-\-no-color\fR
39 Do not interpret ANSI color and style sequences.
40 .TP
41 \fB\-d\fR, \fB\-\-differences\fR[=\fIpermanent\fR]
42 Highlight the differences between successive updates. If the optional
43 \fIpermanent\fR argument is specified then \fBwatch\fR will show all changes
44 since the first iteration. The \fIpermanent\fR argument needs to be linked to
45 the option, such as \fB\-d1\fR or \fB\-\-differences=1\fR.
46 .TP
47 \fB\-e\fR, \fB\-\-errexit\fR
48 Freeze updates on \fIcommand\fR error, and exit after a key press. The exit code
49 of \fBwatch\fR will be the code \fIcommand\fR exits with. If signal \fBn\fR is
50 the cause of \fIcommand\fR termination, the exit code will be 128 + \fBn\fR.
51 .TP
52 \fB\-f\fR, \fB\-\-follow\fR
53 Instead of clearing the screen at each update, \fBwatch\fR will scroll the
54 output similar to how \fItail -f\fR works. This option is not compatible
55 with any option tracking the output of the screen, such as the
56 \fB\-\-differences\fR, \fB\-\-chgexit\fR and \fB\-\-eqexit\fR options.
57 .TP
58 \fB\-g\fR, \fB\-\-chgexit\fR
59 Exit when the visible output of \fIcommand\fR changes. Changes that are off
60 the screen due to small screen size or large output will not cause \fBwatch\fR
61 to exit.
62 .TP
63 \fB\-n\fR, \fB\-\-interval\fR \fIseconds\fR
64 Specify update interval. Values smaller than 0.1 and larger than 2678400 (31
65 days) are converted into these respective bounds. Both '.' and ',' work for any
66 locale. The \fBWATCH_INTERVAL\fR environment variable can be used to
67 persistently set a non-default interval (following the same rules and
68 formatting).
69 .TP
70 \fB\-p\fR, \fB\-\-precise\fR
71 Execute \fIcommand\fR \fB\-\-interval\fR seconds after its previous run started,
72 instead of \fB\-\-interval\fR seconds after its previous run finished. If it's
73 taking longer than \fB\-\-interval\fR seconds for \fIcommand\fR to complete, it
74 is waited for in either case.
75 .TP
76 \fB\-q\fR, \fB\-\-equexit\fR <cycles>
77 Exit when output of \fIcommand\fR does not change for the given number of
78 cycles.
79 .TP
80 \fB\-r\fR, \fB\-\-no-rerun\fR
81 Do not run the program on terminal resize, the output of the program will
82 re-appear at the next regular run time.
83 .TP
84 \fB-s\fR, \fB--shotsdir\fR
85 Directory to save screenshots into.
86 .TP
87 \fB\-t\fR, \fB\-\-no\-title\fR
88 Turn off the header normally shown at the top of the screen.
89 .TP
90 \fB\-w\fR, \fB\-\-no\-wrap\fR
91 Turn off line wrapping. Long lines will be truncated instead of wrapped to the
92 next line.
93 .TP
94 \fB\-x\fR, \fB\-\-exec\fR
95 Pass \fIcommand\fR to an
96 .BR exec (3)
97 call instead of \fBsh \-c\fR. The program will start a bit quicker. Shell
98 features (environment setup, variable and pathname expansion, etc.) will be
99 unavailable.
100 .TP
101 \fB\-h\fR, \fB\-\-help\fR
102 Display help text and exit.
103 .TP
104 \fB\-v\fR, \fB\-\-version\fR
105 Display version information and exit.
106 .SH "KEY CONTROL"
107 .TP
108 .B spacebar
109 Issue \fIcommand\fR immediately. If it's running at the moment, it is not
110 interrupted and its next round will start without delay.
111 .TP
112 .B q
113 Quit \fBwatch\fR. It currently does not interrupt a running \fIcommand\fR (as
114 opposed to terminating signals, such as the SIGKILL following Ctrl+C).
115 .TP
116 .B s
117 Take a screenshot. It will be saved in the working directory, unless specified
118 otherwise by \fB\-\-shotsdir\fR. If \fIcommand\fR is running at the moment, the
119 screenshot will be taken as soon as it finishes.
120 .SH "EXIT STATUS"
121 .TP
122 .B 0
123 Success. Does not represent \fIcommand\fR exit code.
124 .TP
125 .B 1
126 Errors unrelated to \fIcommand\fR operation.
127 .TP
128 .B 2
129 Errors related to \fIcommand\fR execution and management (not its exit code).
130 .TP
131 .B any non-zero (\-\-errexit)
132 With \fB\-\-errexit\fR the last exit code of \fIcommand\fR is returned.
133 .SH ENVIRONMENT
134 The behavior of \fBwatch\fR is affected by the following environment variables.
135 .TP
136 .B WATCH_INTERVAL
137 Update interval, follows the same rules as the \fB\-\-interval\fR command line
138 option.
139 .TP
140 .B COLUMNS
141 Terminal screen character width. Set to override autodetection.
142 .TP
143 .B LINES
144 Terminal screen character height. Set to override autodetection.
145 .SH NOTES
146 POSIX option processing is used (i.e., option processing stops at the first
147 non\-option argument). This means that flags after \fIcommand\fR don't get
148 interpreted by \fBwatch\fR itself.
149 .P
150 Non-printing characters are stripped from program output. Use \fBcat -v\fR as
151 part of the command pipeline if you want to see them.
152 .SH EXAMPLES
153 .PP
154 To watch the contents of a directory change, you could use
155 .IP
156 watch \-d ls \-l
157 .PP
158 If you have CPUs with a dynamic frequency and want to observe it change, try the
159 following. The command is passed to the shell, which allows you to make the
160 pipeline. The quotes are a feature of the shell too.
161 .IP
162 watch \-n1 'grep "^cpu MHz" /proc/cpuinfo | sort -nrk4'
163 .PP
164 To monitor the up status of your servers, saving a copy of the output of each
165 run to a file, you may use this. The \fB\-p\fR makes the command execute every
166 10 seconds regardless of how long it took to complete the previous run.
167 .IP
168 watch \-n10 \-p \-d '{ date; for i in 10.0.0.31 10.0.0.32 10.0.0.33; do R=OK; ping \-c2 \-W2 "$i" &>/dev/null || R=FAIL; echo "$i: $R"; done } | tee \-a ~/log'
169 .PP
170 You can watch for your administrator to install the latest kernel with
171 .IP
172 watch uname \-r
173 .SH BUGS
174 When the terminal dimensions change, its contents changes are not registered on
175 the next \fIcommand\fR run. \fB\-\-chgexit\fR will not trigger that turn and the
176 counter of \fB\-\-equexit\fR will not restart even if \fIcommand\fR output
177 changes meanwhile. \fB\-\-differences\fR highlighting is reset.
178 .SH "REPORTING BUGS"
179 Please send bug reports to
180 .MT [email protected]
181 .ME .