What is dmesg?

dmesg (short for “display message” or “driver message”) is one of the most important and simplest diagnostic tools in any Linux system. It allows you to read messages from the kernel ring buffer.

Think of this buffer as your system’s black box. From the very moment the computer starts, the Linux kernel writes all important information into it: what it has detected, which drivers it has loaded, and whether it has encountered any errors. dmesg is the command that lets us look inside this box.

Why is dmesg so useful?

Unlike standard system logs (e.g., in /var/log), dmesg shows very low-level messages, directly from the kernel. It is indispensable when:

  • The system won’t boot: dmesg can show the last kernel message before a hang.
  • Hardware isn’t working: You plug in a USB drive, and nothing happens? dmesg will show whether the kernel detected it at all and if it tried to load a driver.
  • Random errors appear: Problems with disks, networking, or memory often leave traces right in dmesg.

How to use dmesg? Basic commands

Simply running dmesg in the terminal will return hundreds, or even thousands, of lines. The art is in finding what you’re looking for.

# Display all messages
dmesg

The output is usually too large to analyze. So, let’s use other tools to filter it.

Paging through the output

To comfortably browse the logs, use less.

dmesg | less

You can now scroll up and down with the arrow keys and exit by pressing q.

Filtering for errors

Most often, we are looking for problems. Use grep to filter lines containing words like “error”, “fail”, or “warning”. grep is case-insensitive (-i), so we don’t have to worry about capitalization.

dmesg | grep -i "error"

Practical example: Diagnosing a USB problem

Imagine you plug in an external USB drive and nothing happens. How do you diagnose this?

  1. Open a terminal.
  2. Enter the command that will show new messages in real-time:
    dmesg -w
    
    (or sudo dmesg --follow if -w doesn’t work)
  3. Now, plug in the USB device.
  4. Watch the terminal. You should see a series of new lines, informing you about the detection of a new device.

If you see something like this:

[ 1234.567890] usb 1-2: new high-speed USB device number 3 using xhci_hcd
[ 1234.567990] usb 1-2: New USB device found, idVendor=0bc2, idProduct=ab38
[ 1234.568090] scsi host4: uas

…it means the hardware was detected correctly.

However, if errors appear, e.g., device descriptor read/64, error -110, you now have a specific clue that you can search for on the internet to find a solution.

Coloring and readability

To make reading easier, you can add the --color=always option to grep or use the dmesg tool with the -H (human-readable) option, which formats the output nicely.

dmesg | grep -i --color=always "fail"

Other useful dmesg options

  • dmesg -T: Displays the date and time in a human-readable format (instead of seconds since system boot).
  • dmesg -l err,warn: Shows only error and warning messages.
  • dmesg -c: Displays the logs and then clears the buffer. Be careful with this option!

Summary

dmesg is the absolute foundation of diagnostics in Linux. Before you start looking for a solution to a problem on the internet, always start by checking what your kernel has to say about it. This simple command can save hours of frustration and is the first step to becoming a conscious Linux user.