Bash Change Group
chgrp changes the group that owns a file or directory without touching the user owner, acting as the group-only counterpart to chown.
What chgrp Does
Group ownership determines which set of users, beyond the individual owner, gets the group permission bits on a file. chgrp (change group) reassigns that group, which is useful for shared team directories where several people need consistent access without changing who personally owns each file.
Changing a File's Group
$ ls -l report.pdf
-rw-r----- 1 alice staff 91200 Jul 16 10:05 report.pdf
$ chgrp devs report.pdf
$ ls -l report.pdf
-rw-r----- 1 alice devs 91200 Jul 16 10:05 report.pdfchgrp vs. chown
chown user:group can already change the group as part of a combined command, so chgrp is mostly a convenience for when you only need to touch group ownership and want the intent to be explicit in a script or command history, without any risk of accidentally changing the user too.
Recursive chgrp
$ chgrp -R marketing shared-assets/
$ ls -ld shared-assets/
drwxrwx--- 5 alice marketing 4096 Jul 16 10:10 shared-assets/Checking Group Membership
A non-root user can only set a file's group to one they themselves belong to. Use the groups or id commands to see your current group memberships before attempting a chgrp, especially on shared servers where group assignments vary by team.
Inspecting Groups
$ groups alice
alice : staff devs sudo
$ chgrp finance report.pdf
chgrp: changing group of 'report.pdf': Operation not permitted- Use id -Gn to list every group your current shell session belongs to
- Only root, or the file's owner when they are also a member of the target group, can chgrp successfully
- Pair chgrp with chmod g+rwx to make a shared directory fully usable by the whole group
- Use chgrp --reference=otherfile target to copy the group from an existing file
Exercise: Bash Permissions
In the permission string "-rwxr-xr--", what does the second group of three characters represent?