Is it possible to `tail -f` the output of `dmesg`?
You are probably looking for some combination of messages from various log files. Try:
tail -f /var/log/{messages,kernel,dmesg,syslog}
…to get a pretty good overview of the system. If you want more or less than that, research what log file the messages you want to see are being placed in.
Also look into using multitail
to file and color code and filter multiple log files at once.
Edit: This wasn't very relevant when I answered this, but as this page gets a lot of hits I'm thought it worth mentioning that newer systems running systemd have this.
dmesg -w
On Linux, since kernel kernel 3.5.0 you can use:
dmesg -w
Also on systems with systemd
you can use:
journalctl -kf
Just make it @#$%ing work
- You want to print output of dmesg, constantly, immediately
- Dmesg is printing the kernel ring buffer (see
man dmesg
) - The kernel ring buffer is a special proc file,
/proc/kmsg
(seeman proc
) - Read
/proc/kmsg
directly, iecat /proc/kmsg
.
Now, if you read the friendly proc manual, it'll sternly warn you to let only one user (who must be privileged) read /proc/kmsg
at a time. Whatever syslog implementation you have should be doing this, and presumably it works with dmesg
. I dunno, I'm out of my league here, just paraphrasing the manual. So while this is the "just make it @#$%ing work" way, consider the next couple methods first.
Man page approved: watch + dmesg
On one linux box I use with systemd init*, dmesg.log isn't written to very often, perhaps not at all? The best way I found to read the kernel log buffer continuously is with watch
. Something like this should get you started (adjust for how many lines fit in your terminal):
watch 'dmesg | tail -50'
watch + dmesg + daemon + tail -f
A more convoluted solution might use watch to write dmesg output to file, which you could then tail -f
. You'd probably want this running as a daemon. A proper daemon would also gzip and rotate logs. The following bash code is untested, unworking, and only intended to convey an idea. @Brooks Moses's answer has a working version.
watch 'dmesg >> /var/log/dmesg.log | tail -1'
* tangent, cause this is a question about an apple desktop os: when systemd is around, don't bother with dmesg
; use journalctl -xf
(maybe w/ -n 100
to also show the previous 100 lines)