Linux dmesg Command Tutorial for Beginners (5 Examples)

Do you know the Linux kernel loads several device drivers when the system boots? In fact, when your system is up and running, and you connect a hardware device, then also a corresponding device driver gets loaded. Of course, the kernel also does a lot of other stuff. What if you want to know info related to these kernel activities?

Well, there exists a command – dubbed dmesg – that you can use if you want to access messages printed by kernel. In this tutorial, we will understand how the dmesg tool works using some easy to understand examples.

Linux dmesg command

The dmesg command lets you print or control the kernel ring buffer. Following is its syntax:

dmesg [options]

And here’s how the tool’s man page explains it:

dmesg is used to examine or control the kernel ring buffer. The default action is to display all 
messages from the kernel ring buffer.

Following are some Q&A-styled examples that should give you a better idea on how the dmesg command works.

Q1. How to use dmesg command?

You can start using the dmesg command sans any command line option.

dmesg

For example, here’s a small part of output the command produced in my case:

How to use dmesg command

Q2. How to limit the output only to error and warnings?

If you run dmesg on your system, you’ll observe it outputs plethora of information. Depending upon what you’re looking for, you may want to filter or limit the output. For its part, dmesg offers you this ability through ‘levels.’ Following is the complete list of levels (along with their explanation):

   emerg - system is unusable
   alert - action must be taken immediately
    crit - critical conditions
     err - error conditions
    warn - warning conditions
  notice - normal but significant condition
    info - informational
   debug - debug-level messages

So for example, if you want to limit the output to only error and warnings, you can do that in the following way:

dmesg –level=err,warn

In my case, here’s a part of output the above command produced:

How to limit the output only to error and warnings

Q3. How to make dmesg produce timestamps in output?

Sometimes, you may want a timestamp to be associated with the messages dmesg produces. This can be done using the -T command line option, which produces human readable timestamps.

dmesg -T

Following is an example output:

How to make dmesg produce timestamps in output

So you can see a timestamp is pre-fixed with each message.

Q4. How to make dmesg display info specific to a device?

Suppose you want dmesg to only display info related to eth0 interface. Here’s how you can do that:

dmesg | grep -i eth0

Following is an example output:

How to make dmesg display info specific to a device

Q5. How to make dmesg display only userspace messages?

If you want to limit dmesg’s output only to userspace messages, use the -u command line option.

dmesg -u

How to make dmesg display only userspace messages

Conclusion

Agreed, dmesg is not the kind of command you’ll need everyday. But this is the tool to turn to when someone (whom you’ve asked for help on certain topic) asks you to provide kernel messages. I’ve mostly seen this case in online user forums, where experienced users ask for kernel output.

Here, in this tutorial, we have discussed the dmesg command from beginners point of view (just to get you started). Once you are done practicing all that we’ve discussed here, head to the tool’s man page.

Share this page:

linux dmesg command tutorial for beginners 5 examples 5
linux dmesg command tutorial for beginners 5 examples 6
linux dmesg command tutorial for beginners 5 examples 7
linux dmesg command tutorial for beginners 5 examples 8

نوشته های مشابه