dmesg Command in Linux | Explained

In Linux, the dmesg command is used to print the Kernel messages. These messages are loaded for the specific modules demanded by the user and generated on the startup. The “dmesg” helps to keep track of the loaded module’s integration with the system. In this article, we will cover the usage of the dmesg command in Linux. The content for the article is given below:

What is dmesg Command in Linux?

As discussed earlier, the “dmesg” command is associated with the Kernel messages. The working/usage of the “dmesg” command is associated with the following syntax:


$ dmesg [options]

The “dmesg” keyword represents the command, and the “[options]” entity denotes the options supported by this command.

The options supported by the dmesg command can be retrieved via the command:

$ dmesg --help

All the option for the dmesg command has been displayed.

How to Use dmesg Command in Linux?

This section presents the various usages of the dmesg command in Linux through examples.

Example 1: Receiving Kernel Messages

To check the Kernel messages, simply type the dmesg command with “sudo”:

$ sudo dmesg

All the messages related to Kernel operation will be displayed.

By default, the output of the “dmesg” command is colorful, as seen above. However, you can get the colorless output using the flag “–color=never” as described below:

$ sudo dmesg --color=never

The color of the Kernel messages has been removed.

Example 2: Displaying the Messages in Human-Readable Format

To display the Kernel messages in a human-readable format, such as time and date, you can use the “H” and “T” options:

$ sudo dmesg -H

In the above image, the date and time have been displayed.

You can get the time of the specific Kernel message as well:

$ sudo dmesg -T

The date and time, along with the days, have been displayed as shown in the below image.

Example 3: Monitoring Real-Time Logs (Events)

To display the real-time messages (events happening in the kernel) means to print the messages as soon as they arrive is obtained as follows:

$ sudo dmesg --follow

This command will repeatedly display the messages until you stop it.

Example 4: Searching For Specific words in Kernel Messages

You can also search for the words in the messages using the “grep” command. Suppose we are searching for the “driver” word:

$ sudo dmesg | grep -i driver

All the “driver” words in the Kernel messages have been highlighted. Here “i” option indicates to search insensitive searches.

Example 5: Clearing Log Messages

To clear all the Kernel messages, use the “c” option with the dmesg command:

$ sudo dmesg -c

Once you execute the above command, all the messages will be cleared.

Let’s check Kernel messages now:

$ sudo dmesg

There is no message to display, as seen in the above image.

Example 6: Limiting the Output to the Specific Facility

As there are many facilities (helpers for maintenance, readability, redundancies) such as syslog, daemon, auth, news, etc., you can limit it only to display the specific facility messages as we are doing here for “syslog” only:

$ sudo dmesg -f syslog

Only syslog related message has been displayed.

You can also use multiple facilities separated by a comma:

$ sudo dmesg -f syslog,daemon

Messages related to both facilities have been displayed.

Example 7: Collaborating the Facility and Level

To display each Kernel facility and level (each message with log levels such as emerg, alert, warn, notice, etc.) explicitly, use the “x”(decode) option as follows:

$ sudo dmesg -x

The messages related to facilities as well as levels have been printed.


In Linux, the dmesg command is a utility that displays the Kernel messages related to the operations. There are different options that can be used with the dmesg command. This post has demonstrated the various usages of the dmesg command in Linux.