Linux chgrp Command: Change a File's Group

chgrp only changes the owner group of a file or directory. It is used when you want multiple users to access the same work files with matching groups.

Even if the group ownership changes, the file's group permission bits are not automatically added. To actually allow shared access, you also need to check the read/write permissions of the target group and the pass-through permissions of the parent directory.

Basic syntax

chgrp [options] group file...

Installed implementations and options may vary depending on the distribution. Check the current system's description using man chgrp.

Examples

Change file group

Verify that the target group exists and that you have permission to change it.

sudo chgrp editors report.txt

Apply to multiple files

Only changes the specified files.

sudo chgrp editors draft.txt final.txt

Check before and after changes

View both group and permissions with stat.

stat -c '%U:%G %A %n' report.txt

Things to check after changing the group

chgrp changes only the group ownership while keeping the owner the same. The group in the example below must already exist, and the calling user must have permission to make the change.

chgrp developers demo.txt
stat -c '%G %n' demo.txt

Example output:

developers demo.txt

If you don't have permission, you may get an Operation not permitted error. Even if the owning group changes, whether you can access the file depends on the file's group permission bits and the current process's group membership. To keep the same group for new files in a shared directory, also check the directory's setgid bit.

Main Options and Format

Options/Format Description
-R Change recursively to subpaths.
-h Targets the group of the symbolic link itself.
--reference=file Uses the group of the referenced file.
-v Show detailed information on processed files.

Precautions when using

Even after changing only the group, Permission denied may appear. Check the execution permissions of the parent directory and the file's group permissions with ls -ld. Since chgrp -R has a wide scope and also considers symbolic link handling, run it only on the precise target.

Frequently Asked Questions

chgrp and chown: Are the groups the same?

Both can be used to change group ownership. If the goal is only to change the group, chgrp makes it clearer.

Official Documentation

You can check the exact behavior of the options and differences in implementation in the official chgrp documentation.