【Linux】Linux下的dmesg命令

本文详细介绍Linux开发中的dmesg命令用法,包括基本打印及通过grep筛选特定事件,如USB设备插入时的日志。理解如何使用选项控制输出并演示了针对USB操作的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在嵌入式Linux的开发过程或桌面端Linux发行版的使用过程中我们经常使用dmesg这一命令进行Linux内核日志的打印.

dmesg 是通过读取kernel中ring buffer的数据,然后将其打印到标准输出(standard output-也就是我们的终端界面进行打印).

命令格式:

dmesg [options]

通常我们是直接运行dmesg命令进行kernel的输出,当日志过多时 我们可以通过Linux下管道的方式进行数据的筛选.
例如我们需要打印当USB插入Linux进行相关操作时,仅是看kernel中关于USB的相关日志,我们可以进行如下操作:

dmesg | grep -i usb
[    3.527421] usb 2-2.1: new full-speed USB device number 4 using uhci_hcd
[    3.648241] usb 2-2.1: New USB device found, idVendor=0e0f, idProduct=0008, bcdDevice= 1.00
[    3.648243] usb 2-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.648243] usb 2-2.1: Product: Virtual Bluetooth Adapter
[    3.648244] usb 2-2.1: Manufacturer: VMware
[    3.648244] usb 2-2.1: SerialNumber: 000650268328
[    6.653018] usbcore: registered new interface driver btusb
[   60.380557] usb 1-1: new high-speed USB device number 2 using ehci-pci
[   60.736237] usb 1-1: New USB device found, idVendor=0e8d, idProduct=2008, bcdDevice= 2.23
[   60.736241] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   60.736243] usb 1-1: Product: X08E
[   60.736245] usb 1-1: Manufacturer: XiaoMi
[   60.736246] usb 1-1: SerialNumber: 28605/A0UF49265

关于更详细的命令参数使用,请运行如下命令进行查看:

t@ubuntu:~$ dmesg --help

Usage:
 dmesg [options]

Display or control the kernel ring buffer.。
...

相关链接:
The dmesg Command

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值