方法一:
最新的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
end2=`dmesg |wc -l` if [ "$end" != "$end2" ]; then
dmesg |awk '{print NR, $0}'|tail -$((end2-end))
end=$end2
fi if [ "$end" -ge ]
then
dmesg -c >/dev/null >&
echo "**********************"
echo "*dmesg -c now; *"
echo "**********************"
end=`dmesg |wc -l`
fi done