返回总目录页

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
  • 
    
    1. ]Initializing ]Initializing ]Initializing ]Linux3.11013generic()(4.81(/ .-))#20-Ubuntu SMP Wed Oct 23 17:26:33 UTC 2013
    2. Ubuntu3.11013.20generic3.116 ]:
    3. ]IntelGenuineIntel
    4. ]AuthenticAMD
    5. ]Geodeby ]CyrixCyrixInstead
    6. ]CentaurCentaurHauls
    7. ]TransmetaGenuineTMx86
    8. ]TransmetaTransmetaCPU
    9. ] ]:-:
    10. ]-:[0x00000000000000000x000000000009fbff usable
    11. ]-:[0x00000000000f00000x00000000000fffff reserved
    12. ]-:[0x00000000001000000x000000007dc08bff usable
    13. ]-:[0x000000007dc08c000x000000007dc5cbff ACPI NVS
    14. ]-:[0x000000007dc5cc000x000000007dc5ebff ACPI data
    15. ]-:[0x000000007dc5ec000x000000007fffffff reserved
    16. ]-:[0x00000000e00000000x00000000efffffff reserved
    17. ]-:[0x00000000fec000000x00000000fed003ff reserved
    18. ]-:[0x00000000fed200000x00000000fed9ffff reserved
    19. ]-:[0x00000000fee000000x00000000feefffff reserved
    20. ]-:[0x00000000ffb000000x00000000ffffffff reserved
    21. ]( ):2. 列出所有被检测到的硬件

     

    1. root@tecmintcom dmesg grep sda
    2. ]2000 sda - logical blocks 250/ )
    3. ]2000 sda off
    4. ]2000 sda :003a0000
    5. ]2000 sda cache enabled read cache enabled doesn注解 ‘sda’表示第一块 SATA硬盘,‘sdb’表示第二块SATA硬盘。若想查看IDE硬盘搜索‘hda’或‘hdb’关键词。

       

      在‘dmesg’命令后跟随‘head’命令来显示开始几行,‘dmesg | head -20′命令将显示开始的前20行。

       

      
      
    6. root@tecmintcom dmesg head 20
    7. ]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)
    8. ]:
    9. ]IntelGenuineIntel
    10. ]AuthenticAMD
    11. ]Geodeby ]CyrixCyrixInstead
    12. ]CentaurCentaurHauls
    13. ]TransmetaGenuineTMx86
    14. ]TransmetaTransmetaCPU
    15. ] ]:-:
    16. ]-:[0x00000000000000000x000000000009fbff usable
    17. ]-:[0x00000000000f00000x00000000000fffff reserved
    18. ]-:[0x00000000001000000x000000007dc08bff usable
    19. ]-:[0x000000007dc08c000x000000007dc5cbff ACPI NVS
    20. ]-:[0x000000007dc5cc000x000000007dc5ebff ACPI data
    21. ]-:[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. 搜索包含特定字符串的被检测到的硬件

 

  1. root@tecmintcom log dmesg grep i usb
  2. root@tecmintcom log dmesg grep i dma
  3. root@tecmintcom log dmesg grep i tty
  4. root@tecmintcom log dmesg grep i memory
  1. ]Scanning1for ]:[0x000000000x01ffffff ]Base[]9b00016384
  2. ]:[0x000000000x000fffff ]:[0x378000000x379fffff ]:[0x340000000x377fffff ]:[0x001000000x33ffffff ]:[0x37a000000x37bfdfff ]Early ]:Registered:[0x0009f0000x000effff ]:Registered:[0x000f00000x000fffff ]try'cgroup_disable=memory'if't want memory cgroups
  3. 6. 清空dmesg缓冲区日志

 

  1. root@tecmintcom log dmesg c

在某些发行版中可以使用命令‘tail -f /var/log/dmesg’来实时监控dmesg的日志输出。

 

  • root@tecmintcom log watch 结论:dmesg命令在系统dmesg记录实时更改或产生的情况下是非常有用的。你可以使用man dmesg来获取更多关于dmesg的信息。

     


 

posted @ 2018-08-31 11:40  马昌伟  阅读(4491)  评论(0编辑  收藏  举报
博主链接地址:https://www.cnblogs.com/machangwei-8/