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.

1
  • 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, 2017 at 18:57

1 Answer 1

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
4
  • 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, 2017 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, 2017 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, 2019 at 16:23
  • Ctrl+z or ctrl+c not working in single user Mode...
    – eri
    Sep 1, 2022 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .