chgrp
Change the group ownership of files
TLDR
Change the owner group of a file/directory
Recursively change the owner group of a directory and its contents
Change the owner group of a symbolic link
Change the owner group of a file/directory to match a reference file
SYNOPSIS
chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...
PARAMETERS
-c, --changes
Verbose; like --verbose but only report when a change is made.
-f, --silent, --quiet
Suppress most error messages.
-v, --verbose
Explain what is being done.
-R, --recursive
Operate on files and directories recursively.
-h, --no-dereference
Affect symbolic links themselves instead of the files they reference.
--dereference
Affect the files referenced by symbolic links (this is the default).
--reference=RFILE
Use the group of RFILE instead of specifying a GROUP name or ID.
GROUP
The new group name or numeric Group ID (GID) for the specified files.
FILE...
One or more files or directories whose group ownership is to be changed.
DESCRIPTION
chgrp, short for "change group", is a fundamental Linux command used to modify the group ownership of files and directories. In a multi-user environment, permissions and access control are critical. Files and directories typically have an owner (a user) and an owning group. The chgrp command allows system administrators or file owners to reassign a file's group to a different existing group. This is essential for managing access rights, as file permissions can be set differently for the owner, the owning group, and others. For instance, you might want to give read-write access to a specific team (represented by a group) for a set of project files, while limiting access for everyone else. By changing the group ownership of these files to the team's group, and then adjusting file permissions with chmod, you can achieve the desired access policy. The command supports recursive operations, allowing entire directory trees to have their group ownership altered efficiently. Proper use of chgrp is vital for maintaining a secure and well-organized file system.
CAVEATS
Only the root user or the current owner of a file can change its group. Furthermore, to change a file's group, the owner must also be a member of the new group. On GNU systems, root can change it to any group. Changing group ownership does not automatically alter file permissions (e.g., read, write, execute bits); this requires a separate command like chmod. The specified GROUP must exist in the system's group database (e.g., /etc/group), unless a numeric GID is used.
<B>USING GID INSTEAD OF GROUP NAME</B>
Instead of a symbolic group name, you can specify the new group using its numeric Group ID (GID). This can be useful in environments where group names might be inconsistent or when working with automated scripts. For example, chgrp 5000 myfile.txt would assign the file to the group with GID 5000.
<B>IMPACT ON SETGID BIT</B>
If a file has the setgid bit set, changing its group ownership might remove this bit for security reasons, especially if the owner is not root. For directories, the setgid bit ensures that newly created files and subdirectories within it inherit the group of the parent directory. Changing the group of a directory with chgrp while the setgid bit is active will cause new files to be created with the new group.
HISTORY
The chgrp command has been an integral part of Unix-like operating systems since their early development. It was created to facilitate multi-user environments where different users and groups require distinct access privileges to files and resources. Its functionality is standardized by POSIX (Portable Operating System Interface), ensuring consistent behavior across various Unix-like systems. The GNU core utilities implementation of chgrp, commonly found on Linux distributions, provides additional features and options, such as the --reference flag, which enhance its flexibility and usability.