A few months back I took the time to learn about top, and how to run it efficiently, and felt quite the wiser for it.

It’s time to investigate another core tool and learn to use it efficiently, and this time it’s dmesg. It’s probably safe to say that in most distros, dmesg is part of the util-linux suite. (Edit, 4 p.m.: This is from Arch Linux.)

But it’s also probably safe to say that dmesg is boring. Enter just dmesg at the terminal, and you get an immeasurable list of junk that either helps you solve your problem, or clutters up the landscape.

There are cleverer ways to use dmesg though, and not just by grep ping it.

For example, you know I like color. Try dmesg -L …

Ah, now that is much easier to pick apart. It’s still a mangled mess of data, but it’s in color, at least. 😉

Another thing: It would be nice if the times it showed were calculated against startup, and not just total time running. I want to see differences in times, rather than just arbitrary start points.

Information like that would help me understand what’s taking a long time, what’s holding up the process, and so forth.

dmesg can do that. Here’s dmesg --reltime …

Of course both that and the colorized output are nifty, but still just spatter information across the screen, willy-nilly.

We could pipe dmesg through a pager like most, but wait … here’s dmesg -H …

Skim to the top of the output and check the bold green stamped time. Everything after that should appear as fractional times added to it.

Now you can pinpoint sluggards.

I most often use dmesg to find error messages; that’s what it’s really useful for. Of course, I could grep the output for keywords, like NET for network errors or VGA for graphics knots.

And of course now that I know about the -L flag, it would be easy to just look for red messages. Those are errors, of course.

What would be even more efficient would be if dmesg could censor itself of everything but error messages.

You know what? Yep, you guessed it. Here’s dmesg -H -l err …

Hey, whaddayaknow. I have a couple of errors in my system setup. As luck would have it.

There are other “message levels;” try dmesg -H -l notice too. Good for additional warnings or errors.

“So K.Mandla,” you say. “Just give me something sparkly I can dump into my terminal.”

Okay, let’s combine a few other nifty flags, all at once. Here’s dmesg -deH , which will display a dual time format, colorize, output times in a more understandable fashion, and employ the pager if necessary.

Sparkly enough for you? 😉

We talked about levels; dmesg also filters by “facility.” Here’s dmesg -deH -f daemon …

systemd, front and center. 🙂

Finally, two flags I’ll mention, but won’t show in use, are dmesg -c and dmesg -C .

They’re not terribly dangerous, but they will clear out all the information thus far collected in your kernel ring buffer, which means everything after that will be empty output — until the kernel stashes another message for your perusal.

I can see the function in that though, since error messages occuring after boot might be easier found without stringing through all the past information. dmesg output would be only the latest and greatest.

So there you have it. Use dmesg wisely and it will give you exactly what you want, in a format you can understand, in a split second.

Use it unwisely, and you’ll be wasting your precious time, straining through unwanted information. … 👿

Edit, 4 p.m.: Seems there are some inconsistencies between distros. I’ll double check what Ubuntu/Mint can or can’t do. Just for the record, this is with Arch Linux, util-linux 2.32.2 for x86_64. I am not sure why there should be such strong differences between this and some others. My apologies if the flags don’t work in your version. That rather defeats the purpose of this little essay, now doesn’t it … ? 😦

Edit, 4:15 p.m. It appears the Ubuntu versions are at 2.20.1 for Raring and Saucy. Debian Wheezy is at 2.20.1 as well. The reltime option appears in 2.22, and the color and “human-readable” flags are in 2.23. Again, sorry about the version discrepancies. Usually I work with old, abandoned software, so this really never comes into play. … 😳

Edit, 5:15 p.m.: I did a little checking beyond just release notes, and from a Linux Mint x86_64 live environment, I was able to use the -deH flags with a binary of dmesg extracted from the util-linux package downloaded from the Arch repositories. Barbaric and uncivilized, yes, but what that means is you’re likely to be able to use version 2.23 or later of dmesg with earlier versions of util-linux. Just rip out the binary and transplant it somewhere onto your system. The usual caveats apply, however: Don’t hold me responsible if your machine crashes, if dmesg freaks out and retreats into your bathroom to cry for three hours, or if hackers steal your credit card number. There’s only so much I can do, folks. …