dmesg命令详解
http://linux.cn/article-3587-1.html
dmesg 命令的使用范例
下面我们展示一些最负盛名的‘dmesg’命令工具以及其实际使用举例。‘dmesg’命令的使用语法如下。
- 1. 列出加载到内核中的所有驱动
grep’文字处理工具来处理‘dmesg’命令的输出。由于dmesg日志的输出不适合在一页中完全显示,因此我们使用管道(pipe)将其输出送到more或者less命令单页显示。
- root@tecmintcom dmesg more
- root@tecmintcom dmesg less
-
- ]Initializing ]Initializing ]Initializing ]Linux3.11013generic()(4.81(/ .-))#20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013
- Ubuntu3.11013.20generic3.116 ]:
- ]IntelGenuineIntel
- ]AuthenticAMD
- ]Geodeby ]CyrixCyrixInstead
- ]CentaurCentaurHauls
- ]TransmetaGenuineTMx86
- ]TransmetaTransmetaCPU
- ] ]:-:
- ]-:[0x00000000000000000x000000000009fbff usable
- ]-:[0x00000000000f00000x00000000000fffff reserved
- ]-:[0x00000000001000000x000000007dc08bff usable
- ]-:[0x000000007dc08c000x000000007dc5cbff ACPI NVS
- ]-:[0x000000007dc5cc000x000000007dc5ebff ACPI data
- ]-:[0x000000007dc5ec000x000000007fffffff reserved
- ]-:[0x00000000e00000000x00000000efffffff reserved
- ]-:[0x00000000fec000000x00000000fed003ff reserved
- ]-:[0x00000000fed200000x00000000fed9ffff reserved
- ]-:[0x00000000fee000000x00000000feefffff reserved
- ]-:[0x00000000ffb000000x00000000ffffffff reserved
- ]( ):2. 列出所有被检测到的硬件
- root@tecmintcom dmesg grep sda
- ]2000 sda - logical blocks 250/ )
- ]2000 sda off
- ]2000 sda :003a0000
- ]2000 sda cache enabled read cache enabled doesn注解 ‘sda’表示第一块 SATA硬盘,‘sdb’表示第二块SATA硬盘。若想查看IDE硬盘搜索‘hda’或‘hdb’关键词。
在‘dmesg’命令后跟随‘head’命令来显示开始几行,‘dmesg | head -20′命令将显示开始的前20行。
- root@tecmintcom dmesg head 20
- ]Initializing ]Initializing ]Initializing ]Linux3.11013generic()(4.81(/ .-))#20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013 (Ubuntu 3.11.0-13.20-generic 3.11.6)
- ]:
- ]IntelGenuineIntel
- ]AuthenticAMD
- ]Geodeby ]CyrixCyrixInstead
- ]CentaurCentaurHauls
- ]TransmetaGenuineTMx86
- ]TransmetaTransmetaCPU
- ] ]:-:
- ]-:[0x00000000000000000x000000000009fbff usable
- ]-:[0x00000000000f00000x00000000000fffff reserved
- ]-:[0x00000000001000000x000000007dc08bff usable
- ]-:[0x000000007dc08c000x000000007dc5cbff ACPI NVS
- ]-:[0x000000007dc5cc000x000000007dc5ebff ACPI data
- ]-:[0x000000007dc5ec000x000000007fffffff reserved
在‘dmesg’命令后跟随‘tail’命令(‘ dmesg | tail -20’)来输出‘dmesg’命令的最后20行日志,当你插入可移动设备时它是非常有用的。
- root@tecmintcom dmesg tail 20
- :-0x378 irq PCSPPTRISTATE:--():with swap on devsda2 :- extents1:--::()20002006NetfilterCoreTeam
- 0.50( buckets max:Registered10
- :DisabledPrivacyExtensions
- :LinkisUp1000MbpsFullDuplex :None
- work thread pool up
- work thread pool -:Loaded
- :Loaded
- :Security:-:noIPv6= audit1398268784.59318630 audit_enabled0= auid4294967295= res1
- -:-:-:5. 搜索包含特定字符串的被检测到的硬件
- root@tecmintcom log dmesg grep i usb
- root@tecmintcom log dmesg grep i dma
- root@tecmintcom log dmesg grep i tty
- root@tecmintcom log dmesg grep i memory
- ]Scanning1for ]:[0x000000000x01ffffff ]Base[]9b00016384
- ]:[0x000000000x000fffff ]:[0x378000000x379fffff ]:[0x340000000x377fffff ]:[0x001000000x33ffffff ]:[0x37a000000x37bfdfff ]Early ]:Registered:[0x0009f0000x000effff ]:Registered:[0x000f00000x000fffff ]try'cgroup_disable=memory'if't want memory cgroups
- 6. 清空dmesg缓冲区日志
- root@tecmintcom log dmesg c
在某些发行版中可以使用命令‘tail -f /var/log/dmesg’来实时监控dmesg的日志输出。
- root@tecmintcom log watch 结论:dmesg命令在系统dmesg记录实时更改或产生的情况下是非常有用的。你可以使用man dmesg来获取更多关于dmesg的信息。