Colors with the unix command "watch"?

Some commands that I use display colors, but when I use them with a clock, the colors disappear:

watch -n 1 node file.js 

Is it possible to somehow return the colors?

+49
linux bash ubuntu watch
Sep 25 '10 at 8:55
source share
5 answers

Some newer versions of watch now support color.

For example, watch --color ls -ahl --color .

Related .

+60
Sep 25 '10 at 14:37
source share

You can duplicate the fundamental operation without the excesses of watch in a couple of lines of the shell script.

 $ cat cheapwatch #!/bin/sh # Not quite your Rolex while true ; do clear printf "[%s] Output of %s:\n" "$(date)" "$*" # "$@" <- we don't want to do it this way, just this: ${SHELL-/bin/sh} -c "$*" sleep 1 # genuine Quartz movement done $ ./cheapwatch ls --color # no problem 

In the end, someone very smart will crack the tr command into this script, which separates the control characters, and then forces the user to use --color to disable this logic. Currently, the sheer naivety of this implementation holds a color monster.

If you are in a situation where watch does not have the --color option, and you cannot update the package for any reason, perhaps you can do it.

+9
May 27 '16 at 1:03 a.m.
source share

YES

watches work with color rendition. this is part of the procps package (at least in debian) there is a bugreport here for your question http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=129334 where they answer that you should update the procps package

eg. with ubuntu 11.04 this package works http://packages.debian.org/wheezy/procps

TL; dg

update procps

+8
Dec 10 '11 at 17:32
source share

Do not use watch ... When you use viewers, you may find that they do not write to the terminal and then erase the color. You must use certain program flags to store control codes there.

If you don't know the flags or not, you can make the poor person look:

 while sleep <time>; do clear; <command>; done 

It will have a little flicker (the clock works "double buffered"), but for some things it is quite useful.

You may be tempted to make a double buffered poor person using

 while sleep <time>; do <command> > /tmp/file; clear; cat /tmp/file; done 

But then you again press the function "I do not write to the terminal."

+8
Nov 28 '16 at 16:50
source share

From the instruction manual:

Non-printable characters are removed from the program output. Use "cat -v" as part of the command pipeline if you want to see them.

Although, I'm not sure how to use it.

+1
Sep 25 '10 at 9:00
source share



All Articles