Home > Package & System Management > dmesg

dmesg: Display Kernel Ring Buffer Messages

dmesg is a command that prints the message buffer of the Linux kernel. You can check important events occurring in the kernel, such as the system boot process, hardware detection, driver loading, and system errors. The `-p` option, in particular, outputs messages in raw format, making it easier to use with other tools.

Overview

The dmesg command displays messages stored in the system's kernel ring buffer. These messages record various events that have occurred in the kernel from system boot time to the present, including hardware initialization, driver loading, errors, and warnings. The `-p` option shows these messages in raw format without syslog prefixes, which is useful when piping to scripts or other analysis tools.

Key Features

  • View kernel events and log records
  • Check hardware detection and driver loading information
  • Utilize for system problem diagnosis and debugging
  • Provides a raw output option (-p)

Key Options

dmesg offers several options to output and filter kernel messages in various formats.

Output Formats and Filtering

Generated command:

Try combining the commands.

Description:

`dmesg` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Various usage examples of the dmesg command.

Display All Kernel Messages

dmesg

The most basic usage, which outputs the entire content of the kernel ring buffer.

Display Kernel Messages in Raw Format

dmesg -p

Outputs only the pure kernel messages without syslog prefixes, making them easy to parse with other scripts or tools.

Search for 'error' Keyword in Raw Messages

dmesg -p | grep -i error

Outputs raw messages with the `-p` option, then uses `grep` to find lines containing the 'error' keyword. Add the `-i` option for case-insensitive search.

View Messages with Human-Readable Timestamps using `less`

dmesg -T | less

Adds timestamps with the `-T` option and pipes the output to `less` for convenient navigation using scroll and search functionalities.

Monitor New Kernel Messages in Real-Time

dmesg -w

Uses the `-w` option to print current messages and then displays new kernel messages as they occur in real-time.

Tips & Notes

dmesg is very useful for system diagnostics, but there are a few points to note.

Useful Tips

  • **Log Buffer Limitations**: The kernel ring buffer has a limited size, so older messages can be overwritten by newer ones. For permanent log records, it's recommended to check `journalctl` or `/var/log/syslog` (depending on your distribution).
  • **Piping with Other Commands**: You can use it with other commands like `grep`, `less`, and `tail` to find specific information or easily navigate and filter the output.
  • **Checking Boot Messages**: Very useful for diagnosing problems that occurred during system boot. Run `dmesg` immediately after booting to check the initialization process.
  • **Root Privileges**: On most modern systems, regular users can execute `dmesg`. However, depending on system configuration or security policies, root privileges might be required.

Same category commands