How to use the dmesg command in Linux
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.
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:
- emerg - The system is not available
- alert - Action must be done immediately
- crit - Important condition
- err - Error condition
- warn - Warning status
- notice - Normal but meaningful status
- info - Information
- 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.
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.
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:
- Use Journalctl to read the system log on Linux
- Kali Linux commands from AZ and commonly used commands
- 10 most useful Linux commands
You should read it
- How to use the which command in Linux
- 20+ essential Linux security commands
- How to use the stat command on Linux
- 14 interesting Linux commands in Terminal
- Basic Linux commands everyone needs to know
- The Cat command in Linux
- How to use the last command in Linux
- How to use ss command on Linux
- 11 uses of ps command in Linux
- Instructions for using zforce command on Linux
- How to limit access to su command in Linux
- 12 things Linux is easier to do in the command line than graphical software