> 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/man1/lastcomm.1.md).

# lastcomm.1

`lastcomm` — 显示最近执行的命令

## 名称

`lastcomm`

## 概要

`lastcomm [-EScesu] [-f file] [+format] [command ...] [user ...] [terminal ...]`

## 描述

`lastcomm` 实用程序提供有关先前执行的命令的信息。不带参数时，`lastcomm` 将打印当前记账文件生命周期内记录的所有命令的信息。

以下选项可用：

**`-E`** 打印进程退出的时间。

**`-S`** 打印进程启动的时间。

**`-c`** 打印进程使用的 CPU 时间量。

**`-e`** 打印进程使用的经过时间量。

**`-s`** 打印进程使用的系统时间量。

**`-u`** 打印进程使用的用户时间量。

**`-f`** `file` 从 `file` 读取，而非默认的 **/var/account/acct**。如果 `file` 是单个短横线（"`-`"），`lastcomm` 从标准输入读取记账条目。

带前导加号（"`+`"）的操作数后跟用户自定义的格式字符串，用于指定显示进程启动或退出日期和时间的格式。该格式字符串可包含 strftime(3) 手册页中描述的任何转换说明，以及任意文本。

如果未指定选项，则假定为 `-cS`。如果 `lastcomm` 带参数调用，则仅打印具有匹配 `command` 名称、`user` 名称或 `terminal` 名称的记账条目。例如：

```sh
lastcomm a.out root ttyd0
```

将列出用户 `root` 在终端 `ttyd0` 上执行的所有名为 `a.out` 的命令。

对于每个进程条目，将打印以下信息：

* 运行该进程的用户名。
* 由系统记账功能累积的标志。
* 进程被调用时所用的命令名。
* 进程使用的 CPU（`-c`）、墙上时间（`-e`）、系统（`-s`）或用户（`-u`）时间量（以秒为单位）。
* 进程启动（`-S`）或退出（`-E`）的时间。

标志编码如下：`S` 表示该命令由超级用户执行，`F` 表示该命令在 fork 之后运行，但随后未执行 exec(3)，`D` 表示该命令因生成 `core` 文件而终止，`X` 表示该命令因信号而终止。

默认情况下，记账条目按时间倒序打印，从执行 `lastcomm` 的时刻开始。但是，如果 `lastcomm` 从标准输入读取条目，则条目按读取顺序打印。

## 文件

**/var/account/acct** 默认记账文件

## 实例

命令

```sh
lastcomm -Ee
```

将打印 **/var/account/acct** 中记录的每条命令的退出时间和经过时间，而

```sh
tail -f -c 0 /var/account/acct | lastcomm -f -
```

将打印每个终止命令的详细信息。

## 参见

[last(1)](/man/man1/last.1.md), sigaction(2), strftime(3), [acct(5)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man5/acct.5.md), [core(5)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man5/core.5.md)

## 历史

`lastcomm` 命令首次出现于 3.0BSD。


---

# 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/man1/lastcomm.1.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.
