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.

What is the chgrp command?

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.

More in This Category
Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux wc Command: Count Lines, Words, Characters, and Bytes

Linux wc Command: Count Lines, Words, Characters, and Bytes

Learn how to use the Linux wc command to count lines, words, characters, and bytes in files or standard input, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Linux sudo Command: Run Commands with Elevated or Another User's Privileges

Learn how to use the Linux sudo command to run approved commands with elevated privileges or as another user, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux whatis Command: Show One-Line Command Descriptions

Linux whatis Command: Show One-Line Command Descriptions

Learn how to use the Linux whatis command to display concise descriptions of commands and manual pages, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux groups Command: Show a User's Group Memberships

Linux groups Command: Show a User's Group Memberships

Learn how to show a User's Group Memberships with the Linux groups command, including practical examples, key options, and important precautions.

Linux Tutorial / Search and Process Text with grep, sort, uniq, cut, and wc

Linux Tutorial / Search and Process Text with grep, sort, uniq, cut, and wc

Practice searching, sorting, grouping, extracting, and counting text with grep, sort, uniq, cut, and wc, including reproducible output and key caveats.

Linux zypper Command: Manage Packages on openSUSE and SUSE

Linux zypper Command: Manage Packages on openSUSE and SUSE

Learn how to manage Packages on openSUSE and SUSE with the Linux zypper command, including practical examples, key options, and important precautions.

Linux jobs Command: List Jobs in the Current Shell

Linux jobs Command: List Jobs in the Current Shell

Learn how to list Jobs in the Current Shell with the Linux jobs command, including practical examples, key options, and important precautions.

Linux free Command: Check Memory and Swap Usage

Linux free Command: Check Memory and Swap Usage

Learn how to use the Linux free command to inspect available memory, used memory, cache, and swap usage, with essential options, practical examples, output interpretation, and common troubleshooting tips.

How to Check IP Addresses on Linux

How to Check IP Addresses on Linux

Learn how to check private and public IP addresses on Linux, identify the active interface and route, and distinguish IPv4, IPv6, and externally visible addresses.