6

I have executed

>> watch tree ./

Now my problem is I'm unable to exit from watch - without closing the terminal.

I read man page of watch but they have not mentioned how to exit from watch screen.

Is there is magic key combo that you need to use to exit from watch ?

It's like one those problems you face when you for the first time open vim and don't know how to close it.

jaggi
  • 166
  • 1
  • 9
  • 1
    Watch works like `tail -f`, a command to inspect realtime logfiles, for example: `sudo tail -f /var/log/syslog`. It will not end, unless you type Ctrl-C – Redbob Sep 25 '17 at 18:57

1 Answers1

7

Press Ctrl-C to interrupt watch. Ctrl-C is the general key combination to kill the foreground process in the shell. If that fails (it sometimes does for hung processes), pressing Ctrl-Z and issuing kill -9 %1to kill process number one works.

If you press Ctrl-Z you can do more things:

  • Resume the job to foreground by running fg
  • Resume the job in the background running bg
  • List running jobs using jobs
  • Manipulate the job, as mentioned, using kill
  • Change priority of job using renice
  • Start new jobs, leaving the old running in the background
vidarlo
  • 21,954
  • 8
  • 58
  • 84
  • okay, this works. But did the `watch` developers not give way to exit from it, like what we have key - `q` for exiting from htop/top. I was looking for something like that. – jaggi Sep 25 '17 at 18:47
  • 1
    It does say: By default, watch will run until interrupted. This is unix-ese for ending it with Ctrl-C :) – vidarlo Sep 25 '17 at 18:48
  • * if you prefer you can make your own `watch` with a `while` loop like this: `while true; do clear; tree ./ ; read -t2.0 -s -n1 k;[[ $k == "q" ]]&&break; done` - I wrapped a custom `ps|awk` pipeline this way because "it looks like `top`" I wanted it to behave like it. – Rich Nov 25 '19 at 16:23
  • Ctrl+z or ctrl+c not working in single user Mode... – eri Sep 01 '22 at 15:36