Linux – How to know what to grep for in dmesg

dmesglinuxlogs

I recently had some trouble with a wireless card, and an online forum suggested searching dmesg with grep firmware. That helped, I was able to find the problem immediately! However, the previous hour was spent looking at dmesg and I couldn't identify anything relevant due to the overwhelming quantity of information!

How does on know what to grep for in dmesg?

Sure, this was a hardware issue but I myself would never have thought to grep for the string "firmware". For someone not intimately familiar with the output of dmesg, how might I make some educated guesses about what to grep for?

Best Answer

Something like this would be useful:

dmesg | grep -iC 3 "what you are looking for" 

For example, if looking for your video card, you could try:

dmesg | grep -iC 3 "video"

Or:

dmesg | grep -iC 3 "graphics" 

The C 3 flag will print 3 lines before and after the matched string, just to give you some context on what the results are. But as @tohecz said, there are thousands of possibilities.

All depends on what you are looking for... sound, wifi, usb, serial, reader....

If you expect a usb key to appear in there, you can try grepping for /dev/sd.


Just found this page, that contains sound advice on how to grep stuff in there:

Because of the length of the output of dmesg, it can be convenient to pipe its output to grep, a filter which searches for any lines that contain the string (i.e., sequence of characters) following it. The -i option can be used to tell grep to ignore the case (i.e., lower case or upper case) of the letters in the string. For example, the following command lists all references to USB (universal serial bus) devices in the kernel messages:

dmesg | grep -i usb

And the following tells dmesg to show all serial ports (which are represented by the string tty):

dmesg | grep -i tty

The dmesg and grep combination can also be used to show how much physical memory (i.e., RAM) is available on the system:

dmesg | grep -i memory

The following command checks to confirm that the HDD(s) is running in DMA (direct memory access) mode:

dmesg | grep -i dma
Related Question