Chgrp
Shell command for changing the group of a file
- 2 min read
- 3 chapters
Related on Lably
Through Command (computing) and File system
A file has access permissions for the owning user, a group and for others. Changing the group for a file changes access to it based on users' group memberships.
History
The chgrp command was originally developed as part of the Unix operating system by AT&T Bell Laboratories. It is available in most Unix-like systems, Plan 9, Inferno and IBM i.
The version of chgrp bundled in GNU coreutils was written by David MacKenzie.
Sign in to keep reading
2 more chapters are free with a Lably account.
Use
Generally, the syntax can be described as:
chgrp [<i id="mwMA">options</i>] <i id="mwMQ">group</i> <i id="mwMg">files</i>
- group specifies the group with which the files should be associated; may be either a symbolic name or an identifier
- files specifies one or more files, which may be the result of a glob expression like
*.conf
Options:
-RRecurse through directories-vVerbose output: log the name of each file changed-fForce or forge ahead even if an error occurs
Examples
The following demonstrates changing the group of files matching *.conf to staff – provided the user owns the files (is gbeeker) and is a member of staff. The change will allow members of the group staff to modify the files since the group-class permissions (read/write) will apply, not the others-class permissions (read only).
<span id="mwUQ"></span><span class="gp" id="mwUg">$ </span>ls<span class="w" id="mwUw"> </span>-l<span class="w" id="mwVA"> </span>*.conf <span class="go" id="mwVQ">-rw-rw-r-- 1 gbeeker wheel 3545 Nov 04 2011 prog.conf</span> <span class="go" id="mwVg">-rw-rw-r-- 1 gbeeker wheel 3545 Nov 04 2011 prox.conf</span> <span class="hll" id="mwVw"><span class="gp" id="mwWA">$ </span>chgrp<span class="w" id="mwWQ"> </span>staff<span class="w" id="mwWg"> </span>*.conf </span><span class="gp" id="mwWw">$ </span>ls<span class="w" id="mwXA"> </span>-l<span class="w" id="mwXQ"> </span>*.conf <span class="go" id="mwXg">-rw-rw-r-- 1 gbeeker staff 3545 Nov 04 2011 prog.conf</span> <span class="go" id="mwXw">-rw-rw-r-- 1 gbeeker staff 3545 Nov 04 2011 prox.conf</span>

