

You could also do something similar that's more closely like tail -f with a while loop that executes dmesg -c and sleep 1 forever (see Ben Harris's answer). We could do just dmesg > /tmp/dmesg.log and overwrite the whole file each iteration, but that's a lot of I/O and also risks losing the file if the computer crashes in the middle of an overwrite. There's also a bugfix instead of trying to both dump the output to a file and pipe it to tail (which doesn't work), we're just reading from the newly-written file. You'll need to be root to do that, thus the sudo. The important trick is that we're doing dmesg -c, which clears the ring buffer after it prints - thus, each time through we're only printing what's new since the last time. watch 'sudo dmesg -c > /tmp/dmesg.log tail -n 40 /tmp/dmesg.log' Here's a variant on djeikyb's answer that's actually tested, and fixes a couple of bugs. * 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) watch 'dmesg > /var/log/dmesg.log | tail -1'
COULD NOT RUN LOGTAIL OR SAVE OUTPUT CODE
The following bash code is untested, unworking, and only intended to convey an idea. A proper daemon would also gzip and rotate logs. You'd probably want this running as a daemon. Something like this should get you started (adjust for how many lines fit in your terminal): watch 'dmesg | tail -50'Ī more convoluted solution might use watch to write dmesg output to file, which you could then tail -f. 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. So while this is the "just make it work" way, consider the next couple methods first. I dunno, I'm out of my league here, just paraphrasing the manual. Whatever syslog implementation you have should be doing this, and presumably it works with dmesg. 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. Read /proc/kmsg directly, ie cat /proc/kmsg.The kernel ring buffer is a special proc file, /proc/kmsg (see man proc).Dmesg is printing the kernel ring buffer (see man dmesg).You want to print output of dmesg, constantly, immediately.
