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 updates

I check and see that Frank doesn’t belong to the group prod:

    % groups frank
    frank : mgrs book ora

I 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 updates

Now 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.)

Get WYNTK: UNIX System Admininistrator now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.