What is dmesg in Linux, And How Do I Use It?

If you have been using Linux for some time, you will likely have come to appreciate how stable and configurable it is, especially if you have some idea of managing a Linux system well. One such tool in managing a system is checking the dmesg kernel log regularly, and especially when there is a problem with the system. The first place to go to is often the dmesg log.

In this tutorial, you will learn:

  • How to access the dmesg kernel log
  • How to use standard date and timestamps instead of the default (the number seconds since kernel was started)
  • What sort of information you can see in the kernel log

What is dmesg, And How Do I Use It?

What is dmesg, And How Do I Use It?

Software requirements and conventions used



Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Linux Distribution-independent
Software Bash command line, Linux based system
Other Any utility which is not included in the Bash shell by default can be installed using sudo apt-get install utility-name (or yum install for RedHat based systems)
Conventions # – requires linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires linux-commands to be executed as a regular non-privileged user

How to access the dmesg kernel log



To access the dmesg kernel log, simply execute the dmesg command from your console prompt, no administrative (root) privileges are required (by default) to access the log:

$ dmesg
...
[64283.356724] INFO: task cp:647102 blocked for more than 120 seconds.
...
[97931.332991] ACPI: Preparing to enter system sleep state S3
[97931.704526] PM: Saving platform NVS memory
[97931.704591] Disabling non-boot CPUs ...
[97931.707220] smpboot: CPU 1 is now offline
...
[97931.746603] ACPI: Low-level resume complete
[97931.746667] PM: Restoring platform NVS memory
[97931.748520] Enabling non-boot CPUs ...
[97931.748551] x86: Booting SMP configuration:
[97931.748551] smpboot: Booting Node 0 Processor 1
...

Whenever you insert a new disk into the system, put the system to sleep, or do many other things, the kernel log will keep track of these events and record them for later review. Simply executing dmesg at the command prompt brings up all information, in chronological order, with a leading time index since the system (or more specifically; the kernel) started, in the format of seconds.milliseconds.

The dmesg kernel log with regular date and timestamps

You can also request for the log to be printed in a more human-friendly ISO date and timestamp format:

$ dmesg --time-format=iso
...
2021-03-14T13:49:21,917805+11:00 sd 3:0:0:0: [sda] Starting disk
...

Scrolling through the dmesg log

If you want to scroll through the full dmesg output since the start, use a pipe (| more):



Information provided by drivers

Various drivers may also write to the log, and such messages are usually prefixed with a leading tag indicating the driver which is writing information:
$ dmesg
...
[    2.006753] usb 1-6: Product: USB Optical Mouse
...
[   12.197240] snd_hda_intel 0000:01:00.1: bound 0000:01:00.0
...

Conclusion

In this article, we briefly looked at the dmesg kernel log, how to access it, and what sort of information you can obtain from this log. The dmesg log is a primary troubleshooting tool whenever something is amiss with your Linux system. Enjoy dmesg!

For another interesting article close to this topic, see How To Access Manual Pages for Linux Commands. You may also enjoy Using Gnu Screen with Examples.



Comments and Discussions
Linux Forum