dmesg: custom time format

You can't, but you can parse dmesg-output:

dmesg --time-format iso \
| while read datestring rest; do \
  printf '%s\n' "$(date -d "$datestring" +%F-%T) $rest"; done

Yes, you can, e.g. by re-formatting the time with gawk (GNU awk) like this:

dmesg --time-format iso | gawk '{ printf (strftime("+%F-%T",mktime(gensub("[-+T:,]"," ","g",$1)))) ; $1 = ""; print $0}'

dmesg prints iso dates here like this:

2019-09-02T06:10:30,708864+02:00 this is an important message

We strip the first string of special characters then use the mktime function in (g)awk to parse the string into a date, then strftime to format - use your favourite parameters.

This gives something like

+2019-09-02-06:10:30 this is an important message

Small notes:

  • We ignore the time zone here assuming this is obvious since we are running the command locally.

  • Please note that the time given by dmesg can be inaccurate (in fact, sometimes way off) if you suspend and then wake the computer due to the way timestamps are stored, see dmesg(1):

    man 1 dmesg
    

Tags:

Date

Dmesg