Here are some ideas for limited environments
Environments such as embedded or pre-boot, where watch, tail, cat, dd and other commands might not be available, might need different gymnastics.
This is what some lightweight Linux distributions do:
while dmesg -c >> /tmp/dmesg.log; do sleep 0.1; done & tail -f /tmp/dmesg.log
It backgrounds the while loop (with &) while tailing the generated output.
If you can't write to /tmp:
mount -t tmpfs - /tmp
# or
mount -t ramfs - /tmp
# or use /dev/shm instead of /tmp - which is available in newer environments
If you don't have tail, you can
cat /tmp/dmesg.log
# or
dd if=/tmp/dmesg.log
# or
dd if=/tmp/dmesg.log 2>/dev/null
Or you might be in a busybox environment that doesn't have dmesg linked, then just:
busybox dmesg -c
You might also need to
busybox sleep
instead of sleep
If you don't have sleep:
while dmesg -c; do echo >/dev/null; done
If you don't have "dmesg":
while sleep 0.1; do cat -v /proc/kmsg; done
This only works if nothing else is reading from here. You might also have a /dev/kmsg.
Bonus tip:
If you don't know what you have, and you don't have "ls", just:
busybox ls
# or simply:
echo *
4Since linux 3.5, you can do dmesg -w. – Doug Richardson – 2014-09-12T16:10:00.003
2http://unix.stackexchange.com/questions/95842/how-can-i-see-dmesg-output-as-it-changes – Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-08-09T20:07:53.170
1You can do
sudo dmesg >> "$TMPDIR/dmesg.log"; tail -f "$TMPDIR/dmesg.log"
on Mac. – Mint – 2019-10-18T05:58:17.280Perhaps change the accepted answer to Maxim's answer? It is 2020 and most users would like to find that answer first, I think.
– Peter Mortensen – 2020-01-08T02:55:50.917that works fine on my Ubuntu 10.04LTS box. A workaround would be to tail whatever logfile that syslog is putting kernel messages into. – None – 2011-05-26T21:58:10.443
4On Mac OSX, that file is /var/log/kernel.log – None – 2011-05-26T22:01:58.400
@Marc Sorry I added my machine spec now. @bobDevil That is cool, but seems that the output is different from dmesg. However this one looks nicer – Ivan Z. G. Xiao – 2011-05-26T22:06:19.163
1@Anonymous 2: Unfortunately,
kernel.log
does not contain the same output asdmesg
. For example, for a damaged drive, file read errors indmesg
specify exactly which file could not be read, whilekernel.log
unfortunately provides only the less-than-helpful notice:disk0s2: I/O error.
– Ivan Vučica – 2011-10-25T17:41:11.760