How to display correct time in dmesg (hardware clock vs system time)?

One would think that “sudo dmesg -T” would show same time as one see by “date” command.
But no, to make it more confusing, it shows different time (date is same).

   -T, --ctime
          Print human-readable timestamps.

          Be aware that the timestamp could be inaccurate!  The time
          source used for the logs is not updated after system
          SUSPEND/RESUME.

btw. i have not suspend/resume

So what is the most simple, easy to remember way to prefix dmesg lines by same time as the date command so one is not confused when browsing the log?

Sample commands to see the date/time difference:

su
echo TEST > /dev/kmsg;dmesg -T | tail -1;date
exit

why you have 2 different time in linux config ? same for me with your script

timedatectl
hwclock -v

you can sync with hwclock ?

i do not know

hwclock --systohc
hwclock --systohc --localtime

does not seem to have any effect on what i have described, times remains different (when running commands mentioned in OP), i mean hour and minute is different.

Maybe try journalctl --dmesg (-k | --dmesg).

man page: journalctl

1 Like

That was it stargazer, workaround to this issue is not to use dmesg :: but journalctl with -k parameter (or alternative to -k is --dmesg)

   -k, --dmesg
       Show only kernel messages. This implies -b and adds the match "_TRANSPORT=kernel".
journalctl|wc -l
18590
journalctl --dmesg|wc -l
2086

indeed amount of lines was reduced

and the timestaps match my system/local time!

so i guess i should make an alias to dmesg → journalctl -k or something not to be always confused by mismatching time.

$ grep dmesg ~/.bashrc
alias dmesg='journalctl -k;echo "journalctl -k was used, reverse order limited to 10k lines? journalctl -kexn 10000"'