brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: watch -c keeps the colors that a command prints

Watch
~/tips/tip-linux-watch-color

watch -c ls --color=always -l /var/log

Show colored output in watch instead of plain or garbled text.

A command with colored output often turns grey the moment you wrap it in watch. Two separate things cause that, and both have a fix.

First, watch has to interpret the color codes, which is what -c (or --color) asks for. Second, the command has to send them. Many tools drop color when their output is not a terminal, so you force it:

watch -c ls --color=always -l /var/log

Look for a similar flag on the tool you use, such as --color=always for grep:

watch -c "grep --color=always -i error app.log | tail -n 15"

The quotes matter there, because the whole pipeline has to run inside watch on every refresh, and not just the first part of it.

Distributions differ. Upstream watch leaves color off unless you pass -c, while Ubuntu’s build may already show it and offers -C to turn it off. I would still write -c in a script, so it behaves the same elsewhere. BusyBox’s tiny watch, found on Alpine, has neither option. And -c only handles colors and styles, so a program that redraws the whole screen will still look odd.

Further reading: watch(1) manual page

More Watch tips On the watch: Settings > SOS > Fall Detection On the watch: Settings > Noise > Noise Threshold > pick a level Open Camera Remote on the watch High Heart Rate Notifications > threshold watch -e -n 5 curl -fsS -o /dev/null https://example.com/health All Watch tips (17) All topics

Link