← All commands
THE COMMAND REFERENCE

chgrp

Change the group of files.

Last updated

Portable / common

Implementation-level reference; examples are not certified for every installed version.

Overview

chgrp changes the group that a file belongs to. A group lets several users share files: the group permission bits of the file apply to its members. Normal users can only change a file to a group they belong to; the examples use your own primary group so they are safe to run.

Background

The macOS manual says chgrp is expected to be POSIX.2 compatible, and gives no date. Today the name covers GNU chgrp, the chgrp that macOS ships, and the chgrp applet in BusyBox. They agree on a group and on -R.

Examples

Set the group to your own primary group:

chgrp "$(id -g)" notes.txt && echo ok

Apply it to a folder and everything inside it with -R:

chgrp -R "$(id -g)" projects logs && echo ok

Check the result; ls -l shows the group in the fourth column, and id -gn is the name:

chgrp "$(id -g)" notes.txt && test "$(ls -l notes.txt | awk '{print $4}')" = "$(id -gn)" && echo yes

Options

-R
Change the group of folders and everything inside them.

Common mistakes

A normal user can choose only groups they belong to; any other group is refused. chgrp -R can touch a very large number of files, so check the path first. Changing the group does not change the permission bits: the group may still lack the access you want, which chmod g+rw gives. Use chown :group to set the group with chown.

Portability

Only a numeric group and -R are in the Common examples. Group names and numbers work, but names can differ between machines. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.