View Kernel Messages in Linux | dmesg Command (original) (raw)

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.

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:

Option Description Example Usage
-H It provides the human-readable output, making timestamps and information more understandable dmesg -H
-T It shows only human-readable timestamps for each message dmesg -T
-l It filter the messages by log level (e.g., err, warn, info) dmesg -l err
-k It only prints the kernel messages (filter out userspace messages) dmesg -k
-s It specifes the buffer size to read messages dmesg -s 1024
-f It filters the messages by facility (e.g., kern, user, daemon) dmesg -f kern
-r It takes the Raw output and do not decode syslog(2) priority to facility and level dmesg -r
-x It 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

**Command:

sudo dmesg | less

**Output:

Viewing log pages

Here,

2. Colorizing dmesg Output

**Command:

sudo dmesg -L

**Output:

coloring dmesg output

Here,

3. Displaying Human-Friendly Timestamps

**Command:

sudo dmesg -H

**Output:

Human reable timestamps

Here,

**4. Displaying Standard Date and Time Format

**Command:

sudo dmesg -T

**Output:

Standard date and time format

Here,

**5. Monitoring Real-Time Logs

**Command:

sudo dmesg --follow

**Output:

Monitoring real  time logs

**Explanation:

**6. Viewing Specific Number of Messages with Head

**Command:

sudo dmesg | head -10

**Output:

Viewing specific number of messages

**Explanation:

**7. Viewing Last 10 Messages with Tail

**Command:

sudo dmesg | tail -10

**Output:

Viewing last 10 messages with trail

**Explanation:

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:

**Command:

sudo dmesg | grep -i sda

**Output:

Searching for disk related messages

**Explanation:

10. Filtering Messages by Log Level (Info)

**Command:

sudo dmesg -l info

**Output:

Filtering messages by log level

**Explanation:

11. Combining Multiple Log Levels

**Command:

sudo dmesg -l debug,notice

**Output:

Combining multiple log levels

**Explanation:

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:

**13. Filtering Messages for Specific Network Interface (eth0)

**Command:

sudo dmesg | grep -i eth0

**Output:

filtering the message sfor specific network interfaces

**Explanation:

14. Filtering Messages by Facility (daemon)

**Command:

sudo dmesg -f daemon

**Output:

Filtering the messages by facility daemon

**Explanation:

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:

Difference between syslog and dmesg

The following are the difference between syslog and dmesg:

Feature syslog dmesg
**Purpose It is a general logging system for various system messages and events It a command that helps in displays kernel ring buffer messages
**Scope Logs messages from kernel, system services, and applications Logs only kernel messages
**Log Files Stores logs in files like /var/log/syslog, /var/log/messages Does not store logs in files; displays current kernel log
**Persistence Logs are persistent and can be archived for long-term storage Logs are transient and only available until next reboot