I am in ubuntu, when I write dmesg the error messages appear in red, how could I print in the console only those?
--level option described in
-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.
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
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"
journalctl -p 0..3
This looks at similar information a different way. Modify the severity filtering (the
3) but just use numbers 0 through 7 for the same concept as dmesg, without having to remember those keywords.
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