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.

#Jobseeker

Find matching jobs & Auto apply with AI

Hyring
Jobseeker using Hyring to search, apply, and prepare with AI

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.pdf

chgrp 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
Note: A regular user cannot chgrp a file to a group they don't belong to, even if they own the file — the command fails with 'Operation not permitted'. Only root can assign a file to an arbitrary group.
Note: chgrp --reference=otherfile target copies the group from otherfile onto target, which is handy when you want a new file to match the permissions scheme of an existing one.

Exercise: Bash Permissions

In the permission string "-rwxr-xr--", what does the second group of three characters represent?