Previous Table of Contents Next


Module 16
chgrp

DESCRIPTION

The external chgrp command changes the group ID of a file or directory. The group ID is used to inform the system which group has group access permissions to a file. If you are a member of the group that the group ID of a file is set to, then the group access permissions apply to you when you try to access a file.

Each file on the system is identified by a group ID. Members of that group have access to the file as specified by the group permissions. By using the chgrp command you can change which group the access permissions affect.

COMMAND FORMAT

Following is the general format of the chgrp command.

     chgrp [ -hR ] group file_list
     chgrp [ -hR ] group directory_list

BSD (Berkeley)
chgrp [ -fR ] group file_list

Options

The following options may be used to control how chgrp functions.

-h If the file is a symbolic link, change the group of the symbolic link instead of the file pointed to by the link.
-R Forces chgrp to recursively descend the directory trees listed, changing the group ID of files and directories. If a symbolic link is encountered, its group ID is changed but it is not traversed.

BSD (Berkeley)
-f If chgrp fails to change the group or incurs errors, it does not report them to your screen.

Arguments

The following arguments may be passed to the chgrp command.

group The group you wish to permit access to your files or directories. You may provide a group name or a group ID for group. For example, your group name is "ts" and your group ID is "40."
file_list One or more files to change the group ID so a different group can access the files.
directory_list One or more directories to change the group ID so a different group can access the files.

FURTHER DISCUSSION

Usually the system administrator separates users into logical groups based on functionality of departments within the company or project. The /etc/passwd file sets your group ID to a number. The /etc/group file contains this number and its corresponding group name. The file also contains a list of users who may be or become members of that group.

For instance, if you're a member of the ts group when you log in, you are listed in the /etc/passwd file with group ID 40 (fourth colon-separated field). In the /etc/group file there is a line containing 40 (third colon-separated field) and the name of the group (first field). Your login may be listed on this line (fourth field) but it is not required since this is your primary login group. If you are listed on another line, you can also become a member of that group by using the newgrp command.


BSD (Berkeley)
The groups in BSD function differently from the groups in System V. In System V you are in one group at a time. For example, if you are in the ts group when you log in, then permissions on files and directories with ts group IDs apply to your login. Even if you are listed in another group, only your current group ID is checked. Whereas in BSD if you are listed in several groups in the group file, then you are a member of those groups at all times.

If the set-user-ID or set-group-ID mode of a file is turned on, chgrp will clear the mode from the file access permissions. If you are super-user the modes are not cleared.


NOTE:  
You must be the owner or super-user of the file to be able to change its group ID.



RELATED COMMANDS

Refer to the chmod command described in Module 17 and chown described in Module 18.

RELATED FILES

The chgrp command looks up the related group ID for a given group name in the /etc/group file.

APPLICATIONS

The chgrp command is used to change the group ID of a file or directory. It allows you to change which group may access your files. There may be certain sets of files that you need to share with a documentation group. By using the chgrp command you can change the group ID so users in the documentation group can access the files and directories.

TYPICAL OPERATION

In this activity you use the chgrp command to change the group of a file using the group name and then back to its original group using the group ID number. Begin at the shell prompt.

1.  Type chgrp dvlp db and press Return. The development group can now access your db directory. You may have to select a different group from the /etc/group file in place of dvlp. Remember, you have to be a member of the group to change the group ID to a different group.
2.  To see the new group type ls -l db and press Return. Your screen will look like the following display.
     cj> ls -l db
     -rwxr-xr-x  1  mylogin   dvlp     1 Jan 24 07:15 db
3.  Type chgrp 40 db and press Return to change the group for db back to ts. Most users use the name of the group, but you can use the group ID. Again 40 is assumed to be the group ID for your primary group.
4.  Turn to Module 17 to continue the learning sequence.


Previous Table of Contents Next