The owner of a file can change the group that the file belongs to.
If you own a file or directory, you can change the group that it belongs to. You might do this if you want to extend access to someone who belongs to a different group, without having to extend access to the world.
To change the group for a file or directory, use the chgrp command . For example, suppose my coworker Frank wants access to one of my files, called updates. The file is read/writable by its group, but belongs to the group prod:
% ls -lg updates
-rw-rw--- 1 lmui prod 590 Sep 8 10:20 updatesI check and see that Frank doesn’t belong to the group prod:
% groups frank
frank : mgrs book oraI can give read/write permission to the world, but it’s better to restrict it to a group. I change the file to the group book, which both of us belong to:
% chgrp book updates
% ls -lg updates
-rw-rw--- 1 lmui book 590 Sep 8 10:20 updatesNow Frank and all other members of the book group can read and write my file, but the file is still restricted from “outsiders.” (In this example, users who belong to prod, but not to book, can no longer read or write the file.)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access