How to change dmesg output colors in terminal?

There are some nasty colors in dmesg output. How to change this?
Looked into .Xresources and .bashrc, no colors defined there matched what I was searching for.

Asked By: sabdosaleh

||

With a lot of these tools that have been gratuitously colored, the easiest way to uncolor them is to pipe them through cat.

$ dmesg | cat
Answered By: David G.

dmesg colours can be customised using a terminal-colors.d file. You can disable colours for dmesg by creating a file named /etc/terminal-colors.d/dmesg.disable, or build your own colour scheme by creating a file named /etc/terminal-colors.d/dmesg.scheme, containing one line per colour definition, e.g.

subsys red

to set the sub-system prefix to red.

If you don’t have a terminal-colors.d directory, create it first:

sudo mkdir /etc/terminal-colors.d

See the “COLORS” section in man dmesg for the list of colour names supported, and the scheme description in man terminal-colors.d for the values available for colours. To see what the dmesg default colours are, you’ll have to look at its source code, the current defaults are:

static const struct dmesg_color colors[] =
{
    [DMESG_COLOR_SUBSYS]    = { "subsys",   UL_COLOR_BROWN },
    [DMESG_COLOR_TIME]      = { "time",     UL_COLOR_GREEN },
    [DMESG_COLOR_TIMEBREAK] = { "timebreak",UL_COLOR_GREEN UL_COLOR_BOLD },
    [DMESG_COLOR_ALERT]     = { "alert",    UL_COLOR_REVERSE UL_COLOR_RED },
    [DMESG_COLOR_CRIT]      = { "crit",     UL_COLOR_BOLD UL_COLOR_RED },
    [DMESG_COLOR_ERR]       = { "err",      UL_COLOR_RED },
    [DMESG_COLOR_WARN]      = { "warn",     UL_COLOR_BOLD },
    [DMESG_COLOR_SEGFAULT]  = { "segfault", UL_COLOR_HALFBRIGHT UL_COLOR_RED }
};
Answered By: Stephen Kitt
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.