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

# chgrp.1

`chgrp` — 更改组

## 名称

`chgrp`

## 概要

`chgrp [-fhvx] [-R [-H | -L | -P]] group file`

## 描述

`chgrp` 实用程序将每个 `file` 操作数所指定文件的组 ID 设置为 `group` 操作数所指定的组 ID。

以下选项可用：

**`-H`** 如果指定了 `-R` 选项，命令行上的符号链接会被跟随，因此不受该命令影响。（遍历过程中遇到的符号链接不会被跟随。）

**`-L`** 如果指定了 `-R` 选项，所有符号链接都会被跟随。

**`-P`** 如果指定了 `-R` 选项，不跟随任何符号链接。这是默认行为。

**`-R`** 更改以各文件为根的文件层级的组 ID，而不仅仅是文件本身。注意，当使用形如“`.*`”的通配符时，要小心避免意外匹配到指向父目录的“`..`”硬链接。

**`-f`** 强制选项忽略错误（用法错误除外），并且不询问异常模式（除非用户没有适当的权限）。

**`-h`** 如果文件是符号链接，则更改链接本身的组 ID，而不是链接所指向的文件。

**`-v`** 使 `chgrp` 输出详细信息，在组被修改时显示文件。如果 `-v` 标志指定多次，`chgrp` 将打印文件名，后跟旧的和新数字组 ID。

**`-x`** 不遍历文件系统挂载点。

除非指定了 `-R` 选项，否则 `-H`、`-L` 和 `-P` 选项将被忽略。此外，这些选项会相互覆盖，命令的行为由最后指定的选项决定。

`group` 操作数可以是组数据库中的组名，也可以是数字组 ID。如果组名同时也是一个数字组 ID，则该操作数被用作组名。

调用 `chgrp` 的用户必须属于指定的组并且是文件的所有者，或者是超级用户。

如果 `chgrp` 收到 `SIGINFO` 信号（参见 stty(1) 的 `status` 参数），则会显示当前文件名以及旧的和新的组名。

## 文件

**`/etc/group`** 组 ID 文件

## 退出状态

`chgrp` 实用程序成功时退出值为 0，发生错误时大于 0。

## 兼容性

在先前版本的系统中，符号链接没有组。

`-v` 和 `-x` 选项是非标准的，不建议在脚本中使用。

## 参见

chown(2), fts(3), [group(5)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man5/group.5.md), [passwd(5)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man5/passwd.5.md), [groups(7)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man7/groups.7.md), symlink(7), [chown(8)](/man/man8/chown.8.md)

## 标准

`chgrp` 实用程序预期与 IEEE Std 1003.2 ("POSIX.2") 兼容。


---

# 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/chgrp.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.
