Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From man watch:

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

So how do I use cat -v if I want to see the colored output from:

watch ls -al --color
share|improve this question

4 Answers 4

up vote 22 down vote accepted

The right command is

watch --color "ls -a1 --color"

It isn't documented in the man page or the --help screen. I has to use strings to find it.

share|improve this answer
1  
This works! Although it's worth noting, that the --color option has been added quite recently to watch. –  Paweł Gościcki Mar 6 '11 at 7:58
5  
Not in Fedora 15 it doesn't! :( watch: unrecognized option '--color' –  Andy Lee Robinson Sep 30 '11 at 21:56
    
@PawełGościcki What operating system are you using? I can't find anything about a --color option being added to watch. –  Ikke Jan 19 '12 at 9:22
1  
My watch is v0.3.0 and I'm on Ubuntu 10.0 –  Paweł Gościcki Jan 19 '12 at 14:00
2  
I've also version 0.3.0 and for simple "ls --color" the watch command will work but for some reason more complex scenarios do not: watch --color "sudo iwlist wlan0 scanning | egrep 'Quality|ESSID' | egrep --color -i 'foobar|$'"will eat the colors :( –  math Mar 7 '12 at 13:39

If you're using a Mac, like me, watch from Homebrew does not support colour.

What you want is fswatch but it's not Homebrew yet. To install it you'll want to do the slightly more convoluted

https://raw.github.com/mlevin2/homebrew/116b43eaef08d89054c2f43579113b37b4a2abd3‌​/Library/Formula/fswatch.rb

See this SO answer for usage.

share|improve this answer
1  
This only works for the filesystem, while watch applies to a command –  Brice Jan 7 at 15:49

watch doesn't work with color output and I know of no way to make it do it. You can create your own script to emulate it, though.

share|improve this answer

I think it may not be possible with the 'watch' command. Here is a longer way of doing it:

while true; do clear; date;echo;ls -al --color; sleep 2; done

You could put this in a script, for example:

echo "while true; do clear; date;echo;\$*;sleep 2; done" > watch2
chmod +x watch2
./watch2 ls -al --color

To clarify, here's why I think it's not possible with the 'watch' command. See what happens if you use cat -v:

watch "ls -al --color|cat -v"

It shows you the color control characters...which I think is not what you want.

share|improve this answer
    
man watch clearly suggests that it should be possible without dissing watch. –  Paweł Gościcki Mar 29 '10 at 19:27
    
It doesn't say you will be able to see colors. It says you will be able to see the non-printable characters. Try my command as above with cat -v to see what man watch was talking about. –  davr Mar 29 '10 at 20:03
    
OK. It seems I must accept the fact that it's simply impossible. –  Paweł Gościcki Mar 31 '10 at 15:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.