How To Use Linux dmesg Command To Print System Logs?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/use-linux-dmesg-command-print-system-logs/
PINTEREST
PINTEREST
INSTAGRAM

dmesg is used to print and control kernel ring buffer. This explanation may be confusing for the most of the readers. Here simplified explanation. dmesg provides logs for troubleshoot, diagnose or save which is created by Linux kernel. It provides low level messages which is not logged by other subsystems.

Provided Information Type

dmesg command and buffer provides a lot of different type of messages and logs. Here the list of some of them.

  • SCSSI
  • USB
  • Controllers
  • Device Mapper
  • CPU
  • Hard Drive

List and Print dmesg

We will start using dmesg command without an option. This will print all message to the current working shell.

List and Print dmesg

List and Print dmesg

List and Troubleshoot Hard Drive Devices

One of the most used situation for dmesg message is the hard drive low level events. We can see operating system level actions of specified hard disk drive. We will filter with grep command. In this example we will filter device named sda.

List and Troubleshoot Hard Drive Devices

List and Troubleshoot Hard Drive Devices

List and Troubleshoot USB

In order to list and troubleshoot USB and related events in operating system we will use grep too. This will list all log lines those have  the term usb

List and Troubleshoot USB

List and Troubleshoot USB

List and Troubleshoot Memory or RAM message

We can list and print memory or ram related messages with memory term.

List and Troubleshoot Memory or RAM message

List and Troubleshoot Memory or RAM message

Print and List Last 20 Lines

While examining the  dmesg messages we need to look specific time messages. We can print the last 20 lines of message with the last command like below.

LEARN MORE  modprobe, lsmod, modinfo Command Tutorial With Examples To Load, List Linux Kernel Modules

Print and List Last 20 Lines

Print and List Last 20 Lines

Print and List First 20 Lines

We can also print the first 20 lines of the dmesg provided log with the  head command like below.

Print and List First 20 Lines

Print and List First 20 Lines

 

List and Print dmesg Messages in Real Time

We may need to print the logs and messages in real time. There is two way to accomplish this. First if our Linux kernel is newer than 3.5 we can use -w option like below.

Or if it is older than 3.5 we can use tail command like below.

Clear dmesg Message Buffer

If we need to start troubleshooting and storing logs into a clear kernel ring buffer we need to remove existing log. We can use -c option in order to clear the log buffer.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/use-linux-dmesg-command-print-system-logs/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)