Unix groups


Each user is a member of one or more groups. Group memberships can be checked with the groups command.

blogin4:~ $ groups
myaccount prj00012

You can change the group ownership of a file with the chgrp command:

blogin4:~ $ chgrp prj00012 somefile.txt
blogin4:~ $ ls -l somefile.txt
-rw-------  1 myaccount prj00012 237271040 Jul  3  2020 somefile.txt

To recursively change the group of all files in a directory, use chgrp -R.

blogin4:~ $ chgrp -R prj00012 somedirectory

Access for group members

Once a file (or a complete directory) has the desired group ownership, the file may be accessed by other users in the group.

blogin4:~ $ ls -l somefile.txt
-rw-------  1 myaccount prj00012 237271040 Jul  3  2020 somefile.txt
blogin4:~ $ chmod g+r somefile.txt
blogin4:~ $ ls -l somefile.txt
-rw-r-----  1 myaccount prj00012 237271040 Jul  3  2020 somefile.txt


blogin4:~ $ ls -ld somedirectory
drwx------  1 myaccount  prj00012      4096 Jul  3  2020 somedirectory
blogin4:~ $ find somedirectory |xargs chmod g+rX
blogin4:~ $ ls -ld somedirectory
drwxr-x---  1 myaccount  prj00012      4096 Jul  3  2020 somedirectory

Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.