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.