Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

chgrp - change file group ownership

&pagelevel(4)&pagelevel

chgrp changes the user group for a file or a directory. You can only use it if you are the file/directory owner or the POSIX administrator.

Only the POSIX administrator can change the user group for each file as required.

Another user may only change the group for his own files, provided that the user is entered in the /etc/group file as a member of the new group.

If chgrp is called by a user without POSIX administrator permissions, then all set s-bits are reset for the specified files (see chmod).

Syntax


chgrp[ -h][ -R] gid file

-h

If file is a symbolic link, chgrp changes the group ID of the symbolic link itself. Without this option, the group ID of the file referenced by the symbolic link is changed.

-R

(recursive) 
chgrp recursively descends through the specified directories, changing the group ID as it proceeds and traversing any symbolic links that it encounters.

gid

(group id)
New group name or new group ID. gid must appear in /etc/group.

file

Name of the file or directory for which the user group is to be redefined. You can also list any number of files and/or directories.

Error

file: Not super-user
You are not permitted to change the user group of the specified file, since you are not the owner of the file or have not been entered as a member of the specified group. Only the POSIX administrator is authorized to redefine the group for all files.


chgrp: unknown group: gid
The group name you have specified for gid is not in the /etc/group file.

File

/etc/group

The group file /etc/group contains a list of all existing user groups. Each line of this file consists of four colon-separated fields:

groupname:groupid:user,user...

Only the POSIX administrator is permitted to create new user groups and to enter new group members.

Locale

The following environment variables affect the execution of chgrp:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_CTYPE governs character classes, character conversion (shifting) and the behavior of character classes in regular expressions.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example

You are currently working under the login name cindy; this name is entered in the /etc/group file as a member of the user groups ag and prog. At present, you belong to the user group ag as is evident from the fact that the name ag is entered for "group" when you create new files:

$ >file
$ ls -l file
-rw-------   1 CINDY    ag          0   Feb 17 15:48 file

You now wish to change the user group for file; the new group is to be prog. To do this, you change the group for file with chgrp:

$ chgrp prog file
$ ls -l file
-rw-------   1 CINDY    prog        0   Feb 17 15:48 file

See also

chmod, chown, id, newgrp
chown() [4]