VOOZH about

URL: https://www.geeksforgeeks.org/linux-unix/how-to-use-the-dmesg-command-on-linux/

⇱ View Kernel Messages in Linux | dmesg Command - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

View Kernel Messages in Linux | dmesg Command

Last Updated : 15 Nov, 2025

The dmesg (display message) command is used to view kernel messages from the ring buffer, providing insights into hardware detection, driver initialization, and system errors during boot and runtime.

  • Displays low-level kernel and hardware messages not visible in standard logs.
  • Useful for diagnosing hardware failures, driver issues, and boot problems.
  • The kernel messages are stored temporarily in the ring buffer and permanently in /var/log/dmesg.
  • Supports options like -T for readable timestamps and --follow to monitor live kernel events in real time.

Basic Example: View All Kernel Messages

This displays all messages from the kernel ring buffer.

Command:

sudo dmesg

Output:

👁 syntax of dmesg

Key Options of dmesg command

The following are the options of dmesg command with describing its functionality:

OptionDescriptionExample Usage
-HIt provides the human-readable output, making timestamps and information more understandabledmesg -H
-TIt shows only human-readable timestamps for each messagedmesg -T
-lIt filter the messages by log level (e.g., err, warn, info)dmesg -l err
-kIt only prints the kernel messages (filter out userspace messages)dmesg -k
-sIt specifes the buffer size to read messagesdmesg -s 1024
-fIt filters the messages by facility (e.g., kern, user, daemon)dmesg -f kern
-rIt takes the Raw output and do not decode syslog(2) priority to facility and leveldmesg -r
-xIt helps with providing the decode facility and level to human-readable prefixes (e.g., kern.info)dmesg -x

Syntax of the dmesg Command

dmesg [options]

Installation and setup dmesg command

The following are the steps that guides in install and setup the dmesg command:

Step 1: Check if dmesg is Installed

Firstly, whether the dmesg software is already available or not using the following command:

which dmesg

Step 2: Install dmesg

For Debian-based systems (Ubuntu, Mint, etc.):

sudo apt udpate
sudo apt install util-linux

For RedHat-based systems (Fedora, CentOS, etc.):

sudo yum install util-linux

Step 3: Verify dmesg Installation

After installation of dmesg command, verify its successful installation using the following command:

dmesg --version

Basic Usage and Examples of dmesg Command

The dmesg command provides detailed kernel-level information useful for diagnosing hardware, driver, and boot-related issues. Below are common examples demonstrating its basic usage and key functionalities.

1. Viewing Logs Page-Wise with Less

  • Used to scroll through kernel messages conveniently, one page at a time.

Command:

sudo dmesg | less

Output:

👁 Viewing log pages

Here,

  • Displays kernel messages page by page for easier reading.
  • The less pager allows smooth scrolling through long outputs.
  • Prevents terminal overflow and improves readability.

2. Colorizing dmesg Output

  • Adds color to different log types for better visibility and quick identification.

Command:

sudo dmesg -L

Output:

👁 coloring dmesg output

Here,

  • Highlights errors, warnings, and informational messages in different colors.
  • Makes log analysis faster and visually easier.
  • Ideal for distinguishing critical events at a glance.

3. Displaying Human-Friendly Timestamps

  • Converts raw timestamps into seconds and nanoseconds for easier reading.

Command:

sudo dmesg -H

Output:

👁 Human reable timestamps

Here,

  • Displays timestamps in an easily readable format.
  • Shows precise timing of kernel messages since boot.
  • Helps track system events with microsecond accuracy.

4. Displaying Standard Date and Time Format

  • Shows log timestamps in a standard, human-readable date and time format.

Command:

sudo dmesg -T

Output:

👁 Standard date and time format

Here,

  • Converts timestamps into real-world date and time.
  • Useful for correlating kernel messages with system or user actions.
  • Slightly reduces time resolution to improve readability.

5. Monitoring Real-Time Logs

  • Continuously displays new kernel messages as they are generated.

Command:

sudo dmesg --follow

Output:

👁 Monitoring real time logs

Explanation:

  • Works like tail-f for live kernel log updates.
  • Shows new events such as hardware connections or system errors in real time.
  • Useful for monitoring system behavior continuously.

6. Viewing Specific Number of Messages with Head

  • Displays only the first few kernel messages for a concise overview.

Command:

sudo dmesg | head -10

Output:

👁 Viewing specific number of messages

Explanation:

  • Shows the first 10 messages from the kernel log.
  • Useful for reviewing early boot or initialization events.
  • Helps focus on startup information only.

7. Viewing Last 10 Messages with Tail

  • Shows the most recent kernel messages for quick inspection.

Command:

sudo dmesg | tail -10

Output:

👁 Viewing last 10 messages with trail

Explanation:

  • Displays the last 10 kernel log entries.
  • Helps identify recent hardware or system changes.
  • Commonly used for troubleshooting after connecting devices.

8. Case-Insensitive Searching

Finds specific messages without worrying about uppercase or lowercase text.

Command:

sudo dmesg | grep -i usb

Output:

👁 Case insensitive searching

Explanation:

  • Searches for messages containing “USB” or “usb”.
  • Helps verify whether USB devices were detected correctly.
  • Simplifies pattern-based message filtering.

9. Searching for Disk Related Messages

  • Searches kernel messages related to disks or storage devices.

Command:

sudo dmesg | grep -i sda

Output:

👁 Searching for disk related messages

Explanation:

  • Finds log entries related to disk drives (/dev/sda).
  • Displays events like detection, mounting, or disk errors.
  • Commonly used to troubleshoot hard drive or SSD issues.

10. Filtering Messages by Log Level (Info)

  • Displays kernel messages based on their severity or importance level.

Command:

sudo dmesg -l info

Output:

👁 Filtering messages by log level

Explanation:

  • Shows informational messages only.
  • Filters logs to focus on normal system operations.
  • Reduces noise from warnings or errors for clarity.

11. Combining Multiple Log Levels

  • Retrieves kernel messages that match more than one log level.

Command:

sudo dmesg -l debug,notice

Output:

👁 Combining multiple log levels

Explanation:

  • Displays both debug and notice-level messages.
  • Helps developers track both normal and detailed system activities.
  • Useful for performance monitoring and testing.

12. Combining Log Levels (err and warn)

Filters messages to show only errors and warnings for quick issue detection.

Command:

sudo dmesg --level=err,warn

Output:

👁 Combining log levels

Explanation:

  • Shows critical system issues and warnings together.
  • Simplifies troubleshooting by focusing on potential problems.
  • Useful for detecting driver or kernel module errors.

13. Filtering Messages for Specific Network Interface (eth0)

  • Displays messages related to a particular network interface, like eth0.

Command:

sudo dmesg | grep -i eth0

Output:

👁 filtering the message sfor specific network interfaces

Explanation:

  • Filters logs for a specific network adapter.
  • Shows driver loading, link status, and connection issues.
  • Helps in diagnosing network-related problems.

14. Filtering Messages by Facility (daemon)

  • Shows kernel messages categorized under a specific facility.

Command:

sudo dmesg -f daemon

Output:

👁 Filtering the messages by facility daemon

Explanation:

  • Filters logs by facility (e.g., daemon, kernel, system).
  • Helps target messages from a particular source or subsystem.
  • Useful for narrowing log analysis to specific components.

15. Decoding Facility and Level

Displays each log message with readable facility and severity labels.

Command:

sudo dmesg -x

Output:

👁 Decoding the facility and level

Explanation:

  • Adds facility and log level prefixes to each message.
  • Makes it easier to identify where messages come from and their severity.
  • Ideal for advanced log analysis and debugging.

Difference between syslog and dmesg

The following are the difference between syslog and dmesg:

Featuresyslogdmesg
PurposeIt is a general logging system for various system messages and eventsIt a command that helps in displays kernel ring buffer messages
ScopeLogs messages from kernel, system services, and applicationsLogs only kernel messages
Log FilesStores logs in files like /var/log/syslog, /var/log/messagesDoes not store logs in files; displays current kernel log
PersistenceLogs are persistent and can be archived for long-term storageLogs are transient and only available until next reboot


Comment

Explore