🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

chgrp Command

Beginner Permissions & Ownership man(1)

Change group ownership of files

👁 10 views 📅 Updated: Mar 15, 2026
SYNTAX
chgrp [OPTION]... GROUP FILE...

What Does chgrp Do?

chgrp changes the group ownership of files and directories. It is equivalent to the group-only part of chown (:group syntax), but regular users can use chgrp to change group to any group they belong to.

chgrp is commonly used for shared project directories where multiple users need access through group membership. Combined with setgid (chmod g+s), it ensures new files inherit the correct group.

Regular users can change the group to groups they are members of. Changing to other groups requires root.

Options & Flags

OptionDescriptionExample
-R Recursive chgrp -R developers project/
-v Verbose chgrp -v www-data file.php
--reference Copy group from another file chgrp --reference=template.php new.php
-f Suppress error messages chgrp -f developers file.txt

Practical Examples

#1 Change group

Changes the group of the project directory.
$ chgrp developers project/

#2 Recursive group change

Changes group for all files in web directory.
$ sudo chgrp -R www-data /var/www/html/

#3 Shared directory setup

Sets up a shared directory: group ownership and setgid for new files.
$ sudo chgrp -R devteam /shared/ && sudo chmod -R g+rws /shared/

#4 Copy group

Copies the group ownership from one file to another.
$ chgrp --reference=index.php upload.php

#5 Verbose output

Shows each file as its group is changed.
$ chgrp -Rv developers src/
Output: changed group of 'src/main.py' to developers

Tips & Best Practices

Regular users can use chgrp: Unlike chown, regular users can chgrp to any group they belong to (check with groups command).
setgid for shared directories: After chgrp, set setgid: chmod g+s dir/. New files automatically inherit the directory group.
chown does both: chown :groupname file does the same thing. chgrp is mainly useful when non-root users need to change groups.

Frequently Asked Questions

How do I change the group of a file?
chgrp groupname file. For recursive: chgrp -R groupname directory/
Can I use chgrp without sudo?
Yes — if you belong to the target group. Check your groups with the groups command.
How do I set up a shared directory?
chgrp -R team /shared/ && chmod -R g+rws /shared/. The setgid ensures new files inherit the team group.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →