linux 操作系统下 dmesg 命令介绍和使用案例

linux 操作系统下 dmesg 命令介绍和使用案例

dmesg 命令介绍

dmesg 是一个用于查看 Linux 内核消息的命令,主要用于访问内核环形缓冲区中的信息。这些消息通常包括系统启动过程中的硬件检测、设备初始化以及运行时的错误和警告信息

基本用法

您可以简单地在终端中输入 dmesg 命令来查看所有内核消息:

bash

dmesg

常用选项

-T:显示人类可读的时间戳。

bash

dmesg -T

-l:按日志级别过滤输出。例如,仅显示错误和警告信息:

bash

dmesg -l err,warn

-f:按设施过滤输出,例如仅显示内核消息:

bash

dmesg -f kern

-n:设置控制台日志级别,指定显示的最低重要性级别。

bash

dmesg -n 4

-w:持续监视新消息(类似于 tail -f)。

bash

dmesg -w

| less:将输出通过 less 命令分页显示,便于浏览。

bash

dmesg | less

命令介绍

root@meng:/etc/apt# which dmesg
/usr/bin/dmesg
root@meng:/etc/apt# dmesg --help

Usage:
 dmesg [options]

Display or control the kernel ring buffer.

Options:
 -C, --clear                 clear the kernel ring buffer
 -c, --read-clear            read and clear all messages
 -D, --console-off           disable printing messages to console
 -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[=<when>]        colorize messages (auto, always or never)
                               colors are enabled by default
 -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
 -p, --force-prefix          force timestamp output on each line of multi-line messages
 -r, --raw                   print the raw message buffer
     --noescape              don't escape unprintable character
 -S, --syslog                force to use syslog(2) rather than /dev/kmsg
 -s, --buffer-size <size>    buffer size to query the kernel ring buffer
 -u, --userspace             display userspace messages
 -w, --follow                wait for new messages
 -W, --follow-new            wait and print only new messages
 -x, --decode                decode facility and level to readable string
 -d, --show-delta            show time delta between printed messages
 -e, --reltime               show local time and time delta in readable format
 -T, --ctime                 show human-readable timestamp (may be inaccurate!)
 -t, --notime                don't show any timestamp with messages
     --time-format <format>  show timestamp using the given format:
                               [delta|reltime|ctime|notime|iso]
Suspending/resume will make ctime and iso timestamps inaccurate.
     --since <time>          display the lines since the specified time
     --until <time>          display the lines until the specified time

 -h, --help                  display this help
 -V, --version               display version

命令案例

错误及告警

dmesg -l err,warn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lisanmengmeng

蚊子腿也是肉

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值