chgrp Command in Linux: Change File Group Ownership

By 

Updated on

5 min read

Using the chgrp command to change group ownership in Linux

The chgrp command changes the group ownership of files and directories in Linux. Each file is associated with an owner and a group, and the group determines which users share access permissions.

This guide explains how to use chgrp to change group ownership of files, directories, and symbolic links.

chgrp Command Syntax

The syntax for the chgrp command is:

txt
chgrp [OPTIONS] GROUP FILE...
  • GROUP - the name of the new group, or a numeric group ID (GID).
  • FILE... - one or more files or directories.

Unlike the chown command, which changes both user and group ownership, chgrp changes only the group.

Regular users can change the group of a file only if they own the file and only to a group they belong to. Use the id command to list the groups your account belongs to. Administrative users can change the group ownership of any file.

To check the current group ownership of a file, use ls -l :

Terminal
ls -l filename

Change the File Group Ownership

To change the group ownership of a file or directory, invoke chgrp followed by the new group name and the target file:

Terminal
chgrp www-data filename

This changes the group of filename to www-data. By default, chgrp produces no output on success and returns exit code zero.

If the command is run by an unprivileged user who does not own the file or is not a member of the target group, you will get an “Operation not permitted” error. Use -f to suppress that error message.

You can pass multiple files and directories as arguments:

Terminal
chgrp www-data file1 file2 dir1

Use the -v (--verbose) option to print information about each file processed:

Terminal
chgrp -v www-data file1 file2
output
changed group of 'file1' from nginx to www-data
group of 'file2' retained as www-data

The output shows both files because -v reports every processed path, including files whose group already matches the target group.

To print information only about files whose group actually changes, use -c (--changes) instead of -v:

Terminal
chgrp -c www-data file1 file2

You can also use a numeric GID instead of a group name:

Terminal
chgrp 1000 filename

If a group on the system is named with digits, prefix the ID with + to force chgrp to treat it as a numeric GID rather than a group name:

Terminal
chgrp +1000 filename

To find group names and their GIDs on the system, see the groups guide .

By default, chgrp changes the group of the target that a symlink points to, not the symlink itself. For example:

Terminal
chgrp www-data symlink1

If the target cannot be followed because of permissions or protected symlink rules, the command may fail with a “cannot dereference ‘symlink1’: Permission denied” error. Do not disable symlink protection to work around this error.

To change the group ownership of the symlink itself rather than its target, use the -h option:

Terminal
chgrp -h www-data symlink1

Recursively Change Group Ownership

To change the group ownership of all files and directories under a given directory, use the -R (--recursive) option:

Terminal
chgrp -R www-data /var/www

When used recursively, chgrp does not follow symbolic links by default. To also change the group of symlinks encountered during recursion, combine -R with -h:

Terminal
chgrp -hR www-data /var/www

Two additional options control symlink traversal during recursive operations:

  • -H - if the argument to chgrp is a symlink, follow it into the directory it points to.
  • -L - follow every symlink to a directory encountered during recursion.

Avoid -H and -L in most cases, as they can produce unexpected results or create security risks.

Quick Reference

TaskCommand
Change group of a filechgrp GROUP file
Change group of multiple fileschgrp GROUP file1 file2
Use numeric GIDchgrp +1000 file
Verbose outputchgrp -v GROUP file
Show only changed fileschgrp -c GROUP file
Suppress errorschgrp -f GROUP file
Change symlink itselfchgrp -h GROUP symlink
Recursive changechgrp -R GROUP /path
Recursive, change symlink objectschgrp -hR GROUP /path

Troubleshooting

Operation not permitted
You do not own the file or are not a member of the target group. Run with sudo, or use the id command to verify your group memberships.

cannot dereference 'symlink': Permission denied
Symlink protection is enabled (/proc/sys/fs/protected_symlinks = 1). Use -h to change the symlink itself instead of the target.

invalid group
The specified group does not exist. Use getent group to list available groups, or see the groups guide .

Group change has no effect on access
Check the file permissions with ls -l. The group must have the appropriate read, write, or execute bits set for the change to affect access.

FAQ

What is the difference between chgrp and chown?
chown can change both the user owner and the group of a file. chgrp changes only the group. The chown form chown :group file is equivalent to chgrp group file.

Can a regular user run chgrp?
Yes, but only to change the group of files they own, and only to a group they are a member of. Use the id command to see which groups you belong to.

How do I change the group of all files in a directory?
Use the -R flag: chgrp -R GROUP /path/to/directory. This changes the group of the directory itself and all files and subdirectories inside it.

What does the + prefix mean in chgrp +1000 file?
It forces chgrp to treat 1000 as a numeric GID. A plain number like chgrp 1000 file already works as a GID; the + is only needed when a group is named with digits and you want to bypass the name lookup.

How do I verify the group was changed?
Run ls -l filename. The fourth column shows the group owner.

Conclusion

chgrp changes the group ownership of files, directories, and symbolic links. Use -R for recursive changes and -h to target symlinks directly rather than their targets.

For more on managing ownership, see the chown guide , the groups guide , and the guide on Linux file permissions .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page