How to filter the dmesg log to see only the errors

22,681

Solution 1

use --level option described in man dmesg:

  -l, --level list
         Restrict output to the given (comma-separated) list of levels.
         For example:

                dmesg --level=err,warn

         will print error and warning messages only.  For all supported
         levels see the --help output.

Solution 2

Direct Answer

dmesg --level=emerg,alert,crit,err

This is what most people are going to be looking for. Add or remove any from the following list of eight, ordered by severity.

   emerg - system is unusable    
   alert - action must be taken immediately
    crit - critical conditions
     err - error conditions
    warn - warning conditions   
  notice - normal but significant condition
    info - informational    
   debug - debug-level messages

Alternate Answer
I like to use grep to quickly filter dmesg output results and, bonus, you can use it at the end of many show commands. The -i means case insensitive. Reference: https://www.howtogeek.com/449335/how-to-use-the-dmesg-command-on-linux/.

dmesg | grep -i "error"

Another Option

journalctl -p 0..3

This looks at similar information a different way. Modify the severity filtering (the 0 through 3) but just use numbers 0 through 7 for the same concept as dmesg, without having to remember those keywords.
Credit: https://askubuntu.com/a/1245985/192800

The Rabbit Hole
Another way to think of this is to look at the actual log file using any method you choose, instead of working around the limitations of dmesg. This can be done broadly to any file and with limitless potential using things like regular expressions. Here is a demonstration of both approaches to show the last -n number of entries.

tail -n 20 /var/log/dmesg
dmesg | tail -n 20
Share:
22,681

Related videos on Youtube

Ferroao
Author by

Ferroao

Interests: python, R, shiny, javascript, bigdata mongo, SQL

Updated on September 18, 2022

Comments

  • Ferroao
    Ferroao almost 2 years

    I am in ubuntu, when I write dmesg the error messages appear in red, how could I print in the console only those?

  • Marek Sebera
    Marek Sebera about 3 years
    To get most error levels/priorities i'd suggest using dmesg -T --level=emerg,alert,crit,err,warn since the docs mention err,warn but there are more important levels above the err. Of course confirm with dmesg --help to see what log levels you have available.