How to use the dmesg command in Linux

The dmesg command has been used to troubleshoot server and Linux desktops for decades. It's time to start using this handy command!

On a rare occasion, Linux data center servers are not working as usual. Why? Because simply nothing is perfect and when a computer is connected to the network, the user is never sure when the problem will occur. Unfortunately, it is not possible to prevent those incidents from happening. But the good news is that there are tools needed to solve the problem.

For most services (Apache, MySQL, etc.), having individual logs can be useful in connection, authentication, security, and many other issues. But what happens when the system needs to consider the server platform itself? When there is a hardware problem, which log file will you check?

The first thing that people search is a special command that provides a lot of information about different device drivers, loaded during the boot process. Information presented through this command can help users understand what is happening with their Linux system. That's the command dmesg. This tool has been used to troubleshoot server and Linux desktops for decades. It's time to start using this handy command! Let's see how it works through the following article!

Setting

Lucky. dmesg is one of the commands found on every Linux distribution, so there is nothing to install here. Just open a terminal window and start using this useful tool.

How to use dmesg command

From the bash prompt, issue dmesg. Users will see lots of useful information. In fact, there is a lot of information that users don't know what they mean. So how to take advantage of the benefits of dmesg? There are several different ways. The first way is to make the output of dmesg become more or less, as follows:

 dmesg | less 

Running dmesg in this way allows users to skip unnecessary information.

Picture 1 of How to use the dmesg command in Linux

However, even using dmesg in this way is not optimal because there are still tons of other information to be screened. Fortunately, dmesg has several options that allow users to continue to encapsulate that information. Users can limit the output to include errors and warnings only, so as not to screen everything that happens right in your system. How to do this? Take advantage of 'help' from flag levels. There are 8 levels that can be viewed, each level can be combined to create a specific iteration from the output of the dmesg command. The levels are:

  1. emerg - The system is not available
  2. alert - Action must be done immediately
  3. crit - Important condition
  4. err - Error condition
  5. warn - Warning status
  6. notice - Normal but meaningful status
  7. info - Information
  8. debug - Debug level notification

Suppose you just want to see important warnings. Please enter the following command:

 dmesg --level=alert,crit 

Hopefully after running the above command, you will not see any output. If you don't see anything, and you're sure there's a problem, reduce the level to the level of errors and warnings:

 dmesg --level=err,warn 

The following is the information that can be used.

Picture 2 of How to use the dmesg command in Linux

Timestamp

The dmesg command has another handy trick. What if the user wants to know exactly when an error or warning occurred? Fortunately, you can add the -T option to get this information:

 dmesg --level=err,warn -T 

Now the user has a timestamp related to each item.

Picture 3 of How to use the dmesg command in Linux

If you still see too much information, reduce the output of the above command to a lesser level and users can skim through the output easily. If there is no time to read through all the output at a particular time, move it to a file to read later:

 dmesg --level=err,warn -T > dmesg_output 

After that, you can view the output in that file at any time.

Surely after reading this article, readers will want to have dmesg command in their data center administration toolkit. With this easy-to-use tool, you can start troubleshooting your server on a large scale and then start narrowing your search.

Good luck!

See more:

  1. Use Journalctl to read the system log on Linux
  2. Kali Linux commands from AZ and commonly used commands
  3. 10 most useful Linux commands
Update 26 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile