dmesg

dmesg 可以查看linux 内核信息

Linux命令dmesg用来显示开机信息,kernel会将开机信息存储在ring buffer中。您若是开机时来不及查看信息,可利用dmesg来查看。开机信息亦保存在/var/log目录中,名称为dmesg的文件里。


1. 列出加载到内核中的所有驱动

我们可以使用如‘more’。 ‘tail’, ‘less ’或者‘grep’文字处理工具来处理‘dmesg’命令的输出。由于dmesg日志的输出不适合在一页中完全显示,因此我们使用管道(pipe)将其输出送到more或者less命令单页显示。

[root@tecmint.com ~]# dmesg | more

[root@tecmint.com ~]# dmesg | less


2. 列出所有被检测到的硬件

要显示所有被内核检测到的硬盘设备,你可以使用‘grep’命令搜索‘sda’关键词,如下:

[root@tecmint.com ~]# dmesg | grep sda


3.搜索包含特定字符串的被检测到的硬件

由于‘dmesg’命令的输出实在太长了,在其中搜索某个特定的字符串是非常困难的。因此,有必要过滤出一些包含‘usb’ ‘dma’ ‘tty’ ‘memory’等字符串的日志行。grep 命令 的‘-i’选项表示忽略大小写。

[root@tecmint.com log]# dmesg | grep -i usb

[root@tecmint.com log]# dmesg | grep -i dma

[root@tecmint.com log]# dmesg | grep -i tty

[root@tecmint.com log]# dmesg | grep -i memory


参数:

-c:显示信息后,清除ring buffer中的内容;

-s<缓冲区大小>:预设置为8196,刚好等于ring buffer的大小;

-n:设置记录信息的层级。




dmsg的例子:

https://blog.csdn.net/wzb56_earl/article/details/50625705


#!/bin/sh

启动日志记录的时间 

uptime_ts=`cat /proc/uptime | awk '{ print $1}'`

#echo $uptime_ts

#awk -v 是把后面的数当成参数传入 传入的是uptime_ts

dmesg | awk -v uptime_ts=$uptime_ts 'BEGIN {

    now_ts = systime();

    #系统启动时间uptime_ts

    #当前时间now_ts

    #已经启动了多长时间:start_ts

    start_ts = now_ts - uptime_ts;

    #print "system start time seconds:", start_ts;

    #print "system start time:", strftime("[%Y/%m/%d %H:%M:%S]", start_ts);

 }

{

    print strftime("[%Y/%m/%d %H:%M:%S]", start_ts + substr($1, 2, length($1) - 2)), $0

}'

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容