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.

How to use the dmesg command in Linux Picture 1

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.

How to use the dmesg command in Linux Picture 2

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.

How to use the dmesg command in Linux Picture 3

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
3.9 ★ | 7 Vote

May be interested

  • Instructions for using zforce command on LinuxInstructions for using zforce command on Linux
    the gzip command is a popular tool used to compress / decompress files in linux. tipsmake.com presents the basics of this tool in the article: some basic terminal commands in linux mint 11.
  • How to limit access to su command in LinuxHow to limit access to su command in Linux
    if you have added linux to your data center or are just using a single linux machine for your business, you need to make sure it is as secure as possible.
  • 12 things Linux is easier to do in the command line than graphical software12 things Linux is easier to do in the command line than graphical software
    graphical user interfaces (guis) were invented to make life easier for computer users, so it's very common to use them to perform most everyday tasks.
  • 11 df commands in Linux (with example)11 df commands in Linux (with example)
    with the df command in linux, you can easily check your system for details about disk space and file size. these 12 examples of df commands will show you how to do them in detail.
  • How to use the Linux command line on Android with TermuxHow to use the Linux command line on Android with Termux
    android is a very operating system 'capacity with more and more desktop accessibility applications. however, sometimes you want to make some things on android that can be as easy as desktop. fortunately, you can use the termux tool, which builds on the existing infrastructure and provides a command line environment that allows you to install real linux applications on your android device.
  • Instructions for using find command in LinuxInstructions for using find command in Linux
    the find command is one of the most important and handy commands on a linux system. as its name suggests, the command can find files on a linux pc based on a variety of conditions and variables you set.
  • How to use the history command in LinuxHow to use the history command in Linux
    as you spend more and more time in terminal sessions, you will constantly find new commands that make everyday tasks more efficient. the gnu history command is one of them.
  • Instructions for using pstree command on LinuxInstructions for using pstree command on Linux
    pstree is a powerful and useful command to display processes running in linux. like the ps command, it shows all the processes that are currently active on your login system. the main difference is that when running the pstree command, processes are organized into tree sorting instead of lists like using the ps command.
  • The dd command in Linux, How to use the dd commandThe dd command in Linux, How to use the dd command
    dd is a command line utility for unix-like and unix operating systems, with the main purpose of converting and copying files.
  • Use the Top command to see the processes running in LinuxUse the Top command to see the processes running in Linux
    the top command in linux is used to display all processes running in the linux environment. this tutorial shows you how to use the top command through explaining the various parameters available and the content they display.