Does watch
only monitor the visible output of a command? Say I'm in a directory with the following contents:
$ ls
a b c d e f g h i j k l m n
If I run watch -g ls -1
I expect it to exit if a file is added or removed. What actually happens is that it exits only if the file in question is visible in the terminal output of watch
:
$ watch -g ls -1
Every 2.0s: ls -1 Wed Nov 13 16:35:03 2013
a
b
c
d
e
f
Deleting the file m
, which is not visible because of the size of my terminal, does nothing. Deleting a visible file, say d
, causes watch
to exit as expected.
The -g
flag is explained thusly in my man
page:
-g, --chgexit
Exit when the output of command changes.
What's going on? Is this normal? How can I use watch
for commands with long output? I am using watch from procps-ng 3.3.4
which was installed from the Debian repos.
Best Answer
I found this thread titled: Bug#225549: have watch monitor stderr. That thread is from 2008, but it looks like older versions don't support the watching of anything other than STDOUT.
So we're limited to just STDOUT. As for visible there is a lot of language in the
info watch
andman watch
that make me think your observation/assumption is correct.excerpt
Also this bit under BUGS:
If I had to guess I'd think they were storing the visible bits in a buffer between runs, and then analyzing just those characters.
EDIT #1
I debugged this further using
strace
and you can seewatch
reading the output from thels
command so it's internally dropping the change.before I delete the
m
fileafter the
m
file is deleted