dmesg is used to examine or control the kernel ring buffer. The default action is to display all messages from the kernel ring buffer.
Linux内核启动时会加载硬件驱动,在有新硬件时也会加载驱动,如果想要查看内核的活动,可以使用dmesg命令。
Linux内核日志存储在一个ring-buffer中,它的大小是固定的,当队列满时,新的消息会覆盖掉最旧的消息。
实际上,在boot阶段,所有的应用还没有启动,syslogd也未启动,这时内核日志是非常重要的信息。
除了设备初始化日志、内核模块日志,它还会包含一些应用崩溃的相关信息记录,了解dmesg的使用对于调试程序相当重要。
使用了以下级别:
emerg: System is unusable. alert: Action must be taken immediately. crit: Critical conditions. err: Error conditions. warn: Warning conditions. notice: Normal but significant condition. info: Informational. debug: Debug-level messages.使用dmesg -l info仅输出info级别的日志,这不包括更高级别的日志。
'dmesg -l debug,notice’同时输出多种级别的日志。
用户组dmesg根据用户类别对日志进行了分组:
kern: Kernel messages. user: User-level messages. mail: Mail system. daemon: System daemons. auth: Security/authorization messages. syslog: Internal syslogd messages. lpr: Line printer subsystem. news: Network news subsystem.使用`-f(facility)'参数过滤组。
使用 -x(decode) 参数可以输出包括组和日志级别的信息。
清除旧内容对于服务器,本操作请谨慎使用,清除后不会再恢复。
对于嵌入式设备的调试,它会比较清楚地展现当前的log信息。
dmesg -c
显示并清除当前的日志内容。
下次再dmesg时就没有以前的日志了。
对于驱动、硬件模块等调试人员来说,dmesg是一个经常使用的命令。
对于应用程序开发人员来说,它是一个需要掌握的调试程序的技能。
它的使用很简单,达到的效果却很惊人。
How to Use the dmesg Command on Linux Linux dmesg Command Tutorial for Beginners (5 Examples)