方法一:
最新的dmesg版本有一个 -w (-w
, --follow
) 选项,可以实时监控并输出:
$ dmesg -wH
方法二:
watch -n 0.1 "dmesg | tail -n $((LINES-6))"
the $((LINES-6))
part should make it fit nicely into your terminal.
方法三:
#!/bin/bash end=`dmesg |wc -l` while true do sleep 1 end2=`dmesg |wc -l` if [ "$end" != "$end2" ]; then dmesg |awk '{print NR, $0}'|tail -$((end2-end)) end=$end2 fi if [ "$end" -ge 1000 ] then dmesg -c >/dev/null 2>&1 echo "**********************" echo "*dmesg -c now; *" echo "**********************" end=`dmesg |wc -l` fi done