Questions tagged [watch]

watch will execute a program periodically, displaying the output.

watch is part of the procps(/proc filesystem utilities) package.

It can be used to monitor the output of a defined command at a specified interval of time.

Example usage:

watch -n 60 'du -sh /var/spool/mail'
128 questions
198
votes
7 answers

How to use watch command with a piped chain of commands/programs

I usually use watch Linux utility to watch the output of a command repeatedly every n seconds, like in watch df -h /some_volume/. But I seem not to be able to use watch with a piped series of command like: $ watch ls -ltr|tail -n 1 If I do that,…
Tulains Córdova
  • 2,926
  • 4
  • 18
  • 26
191
votes
11 answers

Is there a way to dynamically refresh the less command?

I like the watch command, but it has its limitations. I'm curious to know whether I could mimic the functionality of watch with less. I'm mainly looking for the ability to scroll through my directory as it dynamically gets modified via a running…
Zaid
  • 10,442
  • 13
  • 38
  • 36
79
votes
4 answers

Cygwin has no watch command?

I installed Cygwin on my Windows XP to use some of its commands. Now I what to check a file every 2 minutes and want to use watch for this purpose but I see that Cygwin has no such command. Is this really true? what can I do instead?
ethan
  • 819
  • 1
  • 7
  • 6
58
votes
6 answers

How can I scroll within the output of my watch command?

I use the watch command to see the contents of my directory changing as a script runs on it (via watch ls dir/) It's a great tool, except that I can't seem to scroll down or up to see all of the contents once the number of entries fills the vertical…
Zaid
  • 10,442
  • 13
  • 38
  • 36
49
votes
7 answers

How to run ssh command until succeeded?

Sometimes I restart a device and need to ssh back in when it's ready. I want to run the ssh command every 5 seconds until the command succeeds. My first attempt: watch -n5 ssh [email protected] && exit 1 How can I do this?
Philip Kirkbride
  • 9,816
  • 25
  • 95
  • 167
42
votes
6 answers

Output of 'watch' command as a list

I want to do some simple computation of the number of lines per minute added to a log file. I also want to store the count for each second. What I need is the output of the following command as a list which will be updated every second: watch -n1…
JohnJohnGa
  • 521
  • 1
  • 4
  • 4
40
votes
3 answers

watch command smallest -n interval

What is the smallest interval for the watch command? The man page and Google searches do not indicate what the smallest interval lower limit is. I found through experimentation it can be smaller than 1 second. To test, I ran this command run on a…
Kyle
  • 503
  • 1
  • 4
  • 5
23
votes
10 answers

How can I run `watch` as a background job?

When I run: watch 'cmd >> output.txt' & the job gets suspended by the system: 3569 Stopped (tty output) Is there a workaround?
Juliusz
  • 391
  • 1
  • 2
  • 5
22
votes
3 answers

How to force watch to run under bash

The problem is that when watch is executed it runs sh and I get this error: sh: 1: func1: not found here is the code: #!/bin/bash func1(){ echo $1 } export -f func1 watch func1
Rachid O
  • 343
  • 1
  • 3
  • 9
20
votes
1 answer

watch command not showing colors for 'git status'

I'm trying to get watch to display colors from 'git status'. I've tried running watch with the --color option, as suggested elsewhere here, but, still, watch --color 'git status' doesn't display colors.
Andrei
  • 1,713
  • 1
  • 15
  • 18
16
votes
1 answer

Working solution for ``watch ps aux | grep foo``

watch ps aux | grep foo is not working: bash: syntax error near unexpected token `}' How can I fix this or is there even a better way?
user237201
  • 171
  • 1
  • 1
  • 3
16
votes
2 answers

Reading from a continuously changing logfile

There is /location/of/thefile, which is a continuously changing logfile. The average density of refreshes is 4 per minute, the possible maximal refresh rate could be 30-40 per minute. Every refresh adds 2-5 lines (average), but it could be hundreds…
user6372
14
votes
2 answers

Does watch only monitor the visible output?

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…
terdon
  • 234,489
  • 66
  • 447
  • 667
13
votes
2 answers

Why does `watch` make `ls /tmp` list contents of $HOME?

I'm trying to watch number of files in my /tmp/ directory. For this I thought this command would work: watch sh -c 'ls /tmp/|wc -l' But it appears to work as if ls had no arguments. Namely, I'm in ~, and I get number of files there instead of…
Ruslan
  • 3,290
  • 3
  • 28
  • 49
12
votes
1 answer

'watch'-ing curl yields unexpected output

I'm trying to watch curl for live feedback on HTTP tweaks. However, when I execute the command, the output is garbled with some download stats. I've tried sending curl's stderr to /dev/null, to no avail. When playing with curl on it's own, this…
Andrei
  • 1,713
  • 1
  • 15
  • 18
1
2 3
8 9