> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man8/dmesg.8.md).

# dmesg.8

`dmesg` — 显示内核消息缓冲区

## 名称

`dmesg`

## 概要

`dmesg [-ac] [-t [-f output_fmt]] [-M core [-N system]]`

## 描述

`dmesg` 工具显示内核消息缓冲区的内容。如果未指定 `-M` 选项，则通过 sysctl(3) 接口从当前运行的内核读取缓冲区。否则，从指定的核心文件读取缓冲区，使用指定内核映像（或默认映像）中的名称列表。

选项如下：

**`-a`** 显示消息缓冲区中的所有数据。这包括任何 syslog 记录和 **/dev/console** 输出。

**`-c`** 打印后清除内核缓冲区。

**`-t`** 将时间戳（参见下文的 SYSCTL 变量章节）转换为绝对日期和时间。

**`-f`** 如果同时指定了 `-t`，则使用指定的 `output_fmt` 进行转换（参见 strftime(3) 手册页）。

**`-M`** 从指定的核心中提取与名称列表关联的值。

**`-N`** 如果同时指定了 `-M`，则从指定的系统而不是默认系统（即系统引导时所用的内核映像）提取名称列表。

## SYSCTL 变量

以下 [sysctl(8)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man8/sysctl.8.md) 变量控制内核如何在消息缓冲区中为条目添加时间戳：每个变量旁边显示了默认值。

**`kern.msgbuf_show_timestamp`**: 0 如果设为 0，则不添加时间戳。如果设为 1，则会在消息缓冲区的大多数行中添加 1 秒粒度的时间戳。如果设为 2，则会添加微秒粒度的时间戳。这也可以设置为引导 [loader(8)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man8/loader.8.md) 可调参数。时间戳放置在内核生成的大多数行的开头。某些多行消息只有第一行会标记时间戳。

## 文件

**/var/run/dmesg.boot** 通常是在启动时挂载文件系统后不久获取的缓冲区内容快照

## 参见

sysctl(3), syslogd(8)

## 历史

`dmesg` 工具出现于 3BSD。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man8/dmesg.8.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
