+4 votes
399 views
What it does and how to use the dmesg Linux command

in Linux / Unix by (552k points)
reopened | 399 views

1 Answer

+5 votes
Best answer

1. Use the dmesg command on Linux
2. See Marks and time details with dmesg command

Linux operating systems offer hundreds of commands that have been developed to offer the best administration facilities for users whether at the hardware, software, services or processes level, where each command fulfills a special function and can display better results. What others. We know the reliability and integrity of Linux distributions , but like any operating system or application, the time may come when some of its components fail and instead of wasting time looking for thousands of causes we can take advantage of a command that It will simplify this process and it is the dmesg command..

TechnoWikis will make a complete analysis of what is and how current dmesg in Linux and so we will realize that it becomes a great help tool for all support tasks.

What is dmesg
The dmesg command is used to write kernel messages on Linux and other Unix-like operating systems on a standard output in a much more organized way. Recall that the kernel is the core of the operating system, it is there that the operating system is loaded into memory at the time of starting the computer and the kernel is able to control almost everything in the system. Thanks to this process, numerous messages are generated by the kernel that appear on the display screen during the boot process.

The dmesg command obtains the data by reading the kernel ring buffer. Basically a buffer is a part of the computer's memory that is reserved as a temporary place for data that is sent or received from an external device, such as a hard disk drive, a keyboard, etc., while a ring buffer It is a fixed size buffer in which any new data added will overwrite the oldest data stored there. dmesg is used to examine or control the kernel ring buffer and the default action is to display all messages in the kernel ring buffer..

The messages generated by the kernel are a fundamental part of the diagnostic tasks since, in case of failure of a device, we will have a summary on what happened and thus take the necessary support measures. When connecting or disconnecting a hardware device in the system, thanks to the dmesg command, it will be possible to know the information detected or disconnected in real time and best of all, the dmesg command is available in most operating systems based on Linux and Unix.


1. Use the dmesg command on Linux

Step 1

The basic use of this command is to execute it without parameters:
 Dmesg 
Step 2

This will result in the deployment of all kernel messages: image
Step 3

Due to all the information displayed, it is difficult to carry out some administration task there. We can use the “-H” parameter in order to tell dmesg that the output is readable for users, which will simplify support tasks. There we find much clearer details about the kernel ring.
 dmesg -H 
image
Step 4

Another alternative to perform a dmesg analysis is with the “-w” parameter, which allows us to write a script to analyze the result using a regular expression in order to filter the events for later analysis:
 dmesg -w 
image
Step 5

We can see that the results are generally abundant, it is possible to limit the output only to errors and warnings in order not to analyze everything that happens in the system internally and for this the dmesg command has eight levels to use, where each of them can be combined with the goal of conducting a much more complete and specific search, these levels are:
emerged
The system cannot be used
alert
It is necessary to take action immediately.

crit
Critical conditions

err
Error conditions

warn
Warning conditions

notice
Normal condition, but with possible failures.

info
information.

debug
Debug messages.
Step 6

We can use various types of levels, for example, we can execute the following:
 dmesg --level = alert, info 
image
Step 7

The results depend on the kernel status:
 dmesg --level = err, warn 
image

2. See Marks and time details with dmesg command

Step 1

By using dmesg, it will be possible to know in detail at what time an error or warning occurred thanks to the -T parameter, we can execute it as follows:
 dmesg --level = err, warn -T 
image
Step 2

There we see details of the time and date of the event. We can specify a specific device to display the results generated by dmesg, for this we specify the name of the device as follows:
 dmesg | grep -i enp0s3 
image
Step 3

If we want to limit the output of dmesg only to user space messages, we will use the “-u” option:
 dmesg -u 
image
Step 4

We can make use of text manipulation tools, such as more (more) or les (less) next to 'grep' with the dmesg command, the reason is that the dmesg registry output does not fit on a single page, you can use some of The following options:
 dmesg | more dmesg | less 
image
Step 5

If we want to discover what hard drives the kernel has detected, it is possible to search for the keyword "sda" along with "grep" to display this result like this:
 dmesg | grep sda 
image
Step 6

We can use the “head” parameter together with dmesg in order to show the desired number of start lines, to display only the first 15 lines we execute:
 dmesg | head -15 
image
Step 7

Similarly, if we only want to deploy the last 15 lines, we execute:
 dmesg | tail -15 
Step 8

To search for a particular device or word, it will be possible to filter the lines with specific strings, where the -i option tells the grep command to ignore the case (uppercase or lowercase letters):
 dmesg | grep -i usb dmesg | grep -i dma dmesg | grep -i tty dmesg | grep -i memory 
image
Step 9

To clean the dmesg event buffer we execute:
 dmesg -c 
In this way we have seen how dmesg is a valuable utility to manage everything that happens with the kernel and its components in real time and carry out a much more complete administrative task.

by (3.5m points)
edited

Related questions

+3 votes
1 answer
+3 votes
1 answer
+3 votes
1 answer
asked Nov 9, 2019 in Linux / Unix by backtothefuture (552k points) | 300 views
+3 votes
1 answer
asked Sep 17, 2019 in Linux / Unix by backtothefuture (552k points) | 285 views
+5 votes
1 answer
asked Apr 30, 2020 in Linux / Unix by backtothefuture (552k points) | 308 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users