【Linux命令每日一知】dmesg--内核日志输出

本文详细介绍了Linux系统中dmesg命令的使用方法,包括其功能、参数选项及示例。dmesg用于查看和控制内核环形缓冲区中的日志信息,支持多种输出格式和过滤选项,如按日志级别、时间戳或特定关键字过滤。

2020-07-15 上海

命令解释

dmesg命令用来输出linux内核的相关日志信息

man page: dmesg - print or control the kernel ring buffer

日志内容保存在文件: /var/log/dmesg

内核的日志也有对应的日志级别,可以在日志内容输出的时候使用--level=xx1,xxx2格式来控制

日志级别描述对应命令的参数值
LOG_EMERGsystem is unusableemerg
LOG_ALERTaction must be taken immediatelyalert
LOG_CRITcritical conditionscrit
LOG_ERRerror conditionserr
LOG_WARNINGwarning conditionswarn
LOG_NOTICEnormal, but significant, conditionnotice
LOG_INFOinformational messageinfo
LOG_DEBUGdebug-level messagedebug

比如,输出emerge和error级别的日志,可以使用如下命令:
dmesg --level=error,emerg

通常,主要将dmesg的输出结合grep来进行过滤查询问题,
比如了解内存问题,可以使用如下命令:
dmesg | grep -i memory

参数选项

参数说明
-T输出已读的时间戳
-u控制输出用户空间的日志
-c清除dmesg日志,但是日志保存的位置内容不会被删除

示例

[root@107 ~]# dmesg -h

Usage:
 dmesg [options]

Options:
 -C, --clear                 clear the kernel ring buffer
 -c, --read-clear            read and clear all messages
 -D, --console-off           disable printing messages to console
 -d, --show-delta            show time delta between printed messages
 -e, --reltime               show local time and time delta in readable format
 -E, --console-on            enable printing messages to console
 -F, --file <file>           use the file instead of the kernel log buffer
 -f, --facility <list>       restrict output to defined facilities
 -H, --human                 human readable output
 -k, --kernel                display kernel messages
 -L, --color                 colorize messages
 -l, --level <list>          restrict output to defined levels
 -n, --console-level <level> set level of messages printed to console
 -P, --nopager               do not pipe output into a pager
 -r, --raw                   print the raw message buffer
 -S, --syslog                force to use syslog(2) rather than /dev/kmsg
 -s, --buffer-size <size>    buffer size to query the kernel ring buffer
 -T, --ctime                 show human readable timestamp (could be
                               inaccurate if you have used SUSPEND/RESUME)
 -t, --notime                don't print messages timestamp
 -u, --userspace             display userspace messages
 -w, --follow                wait for new messages
 -x, --decode                decode facility and level to readable string

 -h, --help     display this help and exit
 -V, --version  output version information and exit

Supported log facilities:
    kern - kernel messages
    user - random user-level messages
    mail - mail system
  daemon - system daemons
    auth - security/authorization messages
  syslog - messages generated internally by syslogd
     lpr - line printer subsystem
    news - network news subsystem

Supported log levels (priorities):
   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


For more details see dmesg(q).
[root@107 ~]# dmesg -H
[Jun13 21:27] Linux version 5.5.2-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)) #
[  +0.000000] Command line: BOOT_IMAGE=/vmlinuz-5.5.2-1.el7.elrepo.x86_64 root=UUID=3437f1a0-f850-4f1b-8a7c-819c5f6a29e4 ro crashke
[  +0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[  +0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[root@107 ~]# dmesg -H
[root@107 ~]#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值