Linux dmesg命令使用方法详解
一、命令简介
dmesg(display message)命令用于显示开机信息。kernel 会将开机信息存储在 ring buffer 中。您若是开机时来不及查看信息,可利用 dmesg 来查看。开机信息亦保存在/var/log/dmesg中。
二、使用方法
三、命令选项
| [root@localhost ~]# dmesg --help |
用法:
| dmesg [选项] |
| |
| 显示或控制内核环形缓冲区,选项:-C, --clear 清除内核环形缓冲区(ring butter) -c, --read-clear 读取并清除所有消息-D, --console-off 禁止向终端打印消息-E, --console-on 启用向终端打印消息 |
| |
| -F, --file <文件> 用 文件 代替内核日志缓冲区 |
| -f, --facility <列表> 将输出限制为定义的设施 |
| -H, --human 易读格式输出 |
| -k, --kernel 显示内核消息 |
| -L, --color[=<时机>] 彩色显示消息(auto, always 或 never)默认启用颜色 |
| -l, --level <列表> 限制输出级别 |
| -n, --console-level <级别> 设置打印到终端的消息级别 |
| -P, --nopager 不将输出通过管道传递给分页程序 |
| -p, --force-prefix force timestamp output on each line of multi-line messages |
| -r, --raw 打印原生消息缓冲区 |
| -S, --syslog 强制使用 syslog(2) 而非 /dev/kmsg |
| -s, --buffer-size <大小> 查询内核环形缓冲区所用的缓冲区大小 |
| -u, --userspace 显示用户空间消息 |
| -w, --follow 等待新消息 |
| -x, --decode 将设施和级别解码为可读的字符串 |
| -d, --show-delta 显示打印消息之间的时间差 |
| -e, --reltime 以易读格式显示本地时间和时间差 |
| -T, --ctime 显示易读的时间戳(可能不准确!) |
| -t, --notime 不显示任何消息的时间戳 |
| --time-format <格式> 以指定格式显示时间戳:[delta|reltime|ctime|notime|iso] |
| 挂起/恢复会使 ctime 和 iso 时间戳不精确。 |
| -h, --help display this help |
| -V, --version display version |
| 支持的日志设施: |
| |
| kern - 内核消息 |
| user - 随机的用户级消息 |
| mail - 邮件系统 |
| daemon - 系统守护进程 |
| auth - 安全/认证消息 |
| syslog - syslogd 内部生成的消息 |
| lpr - 行打印机子系统 |
| news - 网络新闻子系统 |
| 支持的日志级别(优先级): |
| |
| emerg - 系统无法使用 |
| alert - 操作必须立即执行 |
| crit - 紧急条件 |
| err - 错误条件 |
| warn - 警告条件 |
| notice - 正常但重要的条件 |
| info - 信息 |
| debug - 调试级别的消息 |
更多信息请参阅 dmesg(1)。
四、常用示例
| (1)将开机信息保存到 boot.msg文件中 |
| dmesg > boot.msg |
| |
| (2)查看警告与报错 |
| dmesg --level=err,warn |
| |
| (3)查看特定类型的日志 |
| dmesg --facility=daemon |
| |
| (4)显示时间,日志级别,类型 |
| dmesg -Tx |
| |
| kern :info : [二 6月 14 16:54:08 2022] DMA32 [mem 0x0000000001000000-0x000000007ffeffff] |
| kern :info : [二 6月 14 16:54:08 2022] Normal empty |
| kern :info : [二 6月 14 16:54:08 2022] Movable zone start for each node |
| kern :info : [二 6月 14 16:54:08 2022] Early memory node ranges |
| kern :info : [二 6月 14 16:54:08 2022] node 0: [mem 0x0000000000001000-0x000000000009efff] |
| kern :info : [二 6月 14 16:54:08 2022] node 0: [mem 0x0000000000100000-0x000000007ffeffff] |
| kern :info : [二 6月 14 16:54:08 2022] Zeroed struct page in unavailable ranges: 114 pages |
| kern :info : [二 6月 14 16:54:08 2022] Initmem setup node 0 [mem 0x0000000000001000-0x000000007ffeffff] |
| kern :debug : [二 6月 14 16:54:08 2022] On node 0 totalpages: 524174 |
| kern :debug : [二 6月 14 16:54:08 2022] DMA zone: 64 pages used for memmap |
| kern :debug : [二 6月 14 16:54:08 2022] DMA zone: 21 pages reserved |
| kern :debug : [二 6月 14 16:54:08 2022] DMA zone: 3998 pages, LIFO batch:0 |
| kern :debug : [二 6月 14 16:54:08 2022] DMA32 zone: 8128 pages used for memmap |
| kern :debug : [二 6月 14 16:54:08 2022] DMA32 zone: 520176 pages, LIFO batch:63 |
| kern :info : [二 6月 14 16:54:08 2022] ACPI: PM-Timer IO Port: 0x4008 |
| |
| **(5)列出所有被检测到的硬件 ** |
| |
| [root@localhost ~] |
| [ 1.308380] sd 0:0:0:0: [sda] 125829120 512-byte logical blocks: (64.4 GB/60.0 GiB) |
| [ 1.308417] sd 0:0:0:0: [sda] Write Protect is off |
| [ 1.308418] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00 |
| [ 1.308486] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA |
| [ 1.319019] sda: sda1 sda2 |
| [ 1.319796] sd 0:0:0:0: [sda] Attached SCSI disk |
| [ 6.562982] XFS (sda1): Mounting V5 Filesystem |
| [ 8.012305] XFS (sda1): Ending clean mount |
| |
参考:
https://www.cnblogs.com/FireLife-Cheng/p/16865908.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY