dmesg command is used to display the kernel related messages on Unix like systems. dmesg stands for “display message or display driver“. dmesg command retrieve its data by reading the kernel ring buffer. While doing troubleshooting on Linux systems, dmesg command becomes very handy, it can help us to identify hardware related errors and warnings, apart from this it can print daemon related messages on your screen.
In this article we will cover 10 useful tips about dmesg command for Linux administrators or geeks, Below is the syntax of dmesg command,
Following are the options that can be used in dmesg command
Let’s jump into the tips part now,
1. Display all messages from kernel ring buffer
Open the terminal and type ‘dmesg’ command and then hit enter. On your screen you will get all the messages from kernel ring buffer.
dmesg command will print all messages but you will only see the latest message that fits on screen, if you want to do the analysis all the logs and display them as page wise then use less or more command,
Output of dmesg command would be something like below,
2. Display messages related to RAM, Hard disk, USB drives and Serial ports
In dmesg command output we can search the messages related to RAM, Hard disk , usb drive and Serial ports.
These above commands can be merged into a single command using multiple grep option (-E), examples is shown below,
Output would be something like below:
3. Read and Clear dmesg logs using (-C) option
If you want to clear dmesg logs after the reading them, then you can use the option -C in dmesg command,
4. Display colored messages (dmesg command output)
Use ‘-L’ option in dmesg command if you want to print the colored messages,
5. Limit the dmesg output to specific facility like daemon
If you want to limit the dmesg output to specific facility like daemon then use the option “–facility=daemon” in dmesg command,
Output of above command would be something like below,
Following are the supported log facilities in dmesg command,
6. Restrict dmesg command output to specific list of levels
Following are specific log levels supported by dmesg command,
Let’s assume we want to display logs related to error and warning, then use “–level” option followed by levels like err & warn, example is shown below
7. Enable timestamps in dmesg logs
There can be some scenarios where we want to enable timestamps in dmesg, this can be easily achieved by using ‘-T’ option in dmesg command.
In case, if you want timestmaps along with decode facility and levels in dmesg command output then use “-Tx” option,
8. Monitor real time dmesg logs using ‘–follow’ option
Use ‘–follow’ option in dmesg command to view real time dmesg logs, example is shown below,
If you want to enable timestamps along real time monitoring of dmesg then use the following command,
9. Display raw message buffer using ‘-r’ option
Use ‘-r’ option in dmesg command to display raw message buffer, example is shown below,
10.Force dmesg command to use syslog
There can be some situations where we want dmesg to get its data from syslog rather than /dev/kmsg. This can be easily achieved using the option “-S“, example is shown below:
dmesg command logs are stored in the file “/var/log/dmesg”
That’s all from this tutorial, I hope these tips help you to understand dmesg command in a better way.