驱动开发中使用函数 printk() 打印的信息可以通过 dmesg 查看

简介

‘dmesg’命令显示linux内核的环形缓冲区信息,我们可以从中获得诸如系统架构、cpu、挂载的硬件,RAM等多个运行级别的大量的系统信息。当计算机启动时,系统内核(操作系统的核心部分)将会被加载到内存中。在加载的过程中会显示很多的信息,在这些信息中我们可以看到内核检测到的硬件设备。

dmesg 命令的使用范例

‘dmesg’命令设备故障的诊断是非常重要的。在‘dmesg’命令的帮助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测或者断开连接的信息。‘dmesg’命令在多数基于Linux和Unix的操作系统中都可以使用。

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

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

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

[root@tecmint.com ~]# dmesg | head  -

在‘dmesg’命令后跟随‘tail’命令(‘ dmesg | tail -20’)来输出‘dmesg’命令的最后20行日志,当你插入可移动设备时它是非常有用的。

[root@tecmint.com ~]# dmesg | tail -

由于‘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

我们可以使用如下命令来清空dmesg的日志。该命令会清空dmesg环形缓冲区中的日志。但是你依然可以查看存储在‘/var/log/dmesg’文件中的日志。你连接任何的设备都会产生dmesg日志输出。

[root@tecmint.com log]# dmesg -c

在某些发行版中可以使用命令‘tail -f /var/log/dmesg’来实时监控dmesg的日志输出。watch -n 2"dmesg | tail -20"表示2s周期性的执行引号的内容

[root@tecmint.com log]# watch -n 2 "dmesg | tail -20"

linux command ------ dmesg的更多相关文章

  1. linux 的dmesg命令

    dmesg命令参考博客 http://www.linuxso.com/command/dmesg.html dmesg用来显示内核环缓冲区(kernel-ring buffer)内容,内核将各种消息存 ...

  2. 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令

    Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...

  3. 《The Linux Command Line》 读书笔记02 关于命令的命令

    <The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...

  4. 《The Linux Command Line》 读书笔记01 基本命令介绍

    <The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...

  5. Linux Command Line Basics

    Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...

  6. Linux Command Line 解析

    Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...

  7. 15 Examples To Master Linux Command Line History

    When you are using Linux command line frequently, using the history effectively can be a major produ ...

  8. 10 Interesting Linux Command Line Tricks and Tips Worth Knowing

    I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...

  9. Reso | The Linux Command Line 的中文版

    http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...

随机推荐

  1. 4556: [Tjoi2016&Heoi2016]字符串

    4556: [Tjoi2016&Heoi2016]字符串 链接 分析: 首先可以二分这个长度.此时需要判断是否存在一个以b结尾的前缀,满足与[c,d]的lcp大于等于mid. 如果我们把串翻转 ...

  2. 【第五课】LNMP环境的入门

    目录 一. LNMP环境介绍 二.Mysql的二进制免编译安装 三.PHP 7.2.5编译部署 四.Nginx的编译安装 五.YUM安装Nginx 一. LNMP环境介绍 LNMP(Linux + N ...

  3. 工具神器推荐 Vox 和 search everything

    工具神器推荐 Vox 和 search everything vox官网: http://www.wox.one/

  4. CS190.1x-ML_lab4_ctr_student

    这次lab主要主要是研究click-through rate (CTR).数据集来自于Kaggle的Criteo Labs dataset.相关ipynb文件见我github. 作业分成5个部分:on ...

  5. Please restart this script from an administrative PowerShell

    问题 在上一篇<MSBUILD : error MSB3428: 未能加载 Visual C++ 组件"VCBuild.exe">,安装时失败了,提示: 解决办法 1. ...

  6. python发送邮件脚本ssl 465端口

    #coding:utf8 from smtplib import SMTP_SSL from email.header import Header from email.mime.text impor ...

  7. Python 四种数值类型(int,long,float,complex)区别及转换

    Python支持四种不同的数值类型,包括int(整数)long(长整数)float(浮点实际值)complex (复数), 数字数据类型存储数值.他们是不可改变的数据类型,这意味着改变数字数据类型的结 ...

  8. What is the difference between WinRT, UWP and WPF?

    在学习UWP的过程中确实有这个迷惑,在此分享一下. UWP (Universal Windows platform), Metro and WinRT are all result of Micros ...

  9. Map Wiki -- proposed by Shuo Ren

    Map Wiki —— 基于Bing地图的生活百科 在旅游.逛街或是闲逛的时,很多时候,我们往往想要对于身边的美食.医院.旅馆.购物.学习.景点等信息有进一步认识.在这时,我们大多会再打开百度或者大众 ...

  10. beta 圆桌 3

    2018-12-16图片缺失,当日数据: 总工作量:24 已完成:5 剩余:19 031602111 傅海涛 1.今天进展 实时字幕的实现大概 2.存在问题 实时字幕存在不稳定和耗费资源 3.明天安排 ...