Selected topic

Chgrp

Permissions

Prefer practical output? Use related tools below while reading.

chgrp is a command-line utility used to change the group ownership of a file or directory on a Linux system. It allows you to modify the group that owns a particular file, which affects the permissions and access control.

Syntax


bash
chgrp [options] group file ...

Options


  • -h : Changes only the symbolic link itself, not what it points to.
  • -R : Recursively changes the group ownership of all files and directories within a directory tree.
  • --from=group : Specify the old group name.

Example Use Cases


  1. Change group ownership for a file
bash
chgrp developers myfile.txt

In this example, we change the group ownership of myfile.txt to developers.

  1. Change group ownership recursively for a directory
bash
chgrp -R developers /var/www/html
Here, we recursively change the group ownership of all files and directories within /var/www/html to developers.
  1. Change group ownership for multiple files
bash
chgrp developers myfile.txt myotherfile.txt
In this example, we change the group ownership of both myfile.txt and myotherfile.txt to developers.

Tips and Variations

  • To specify a new group name, use the syntax chgrp newgroup file.
  • If you want to change the group ownership without changing the permissions, use chmod 664 -R after running chgrp.
  • Be careful when using chgrp, as changing group ownership can affect access control and permissions.

Best Practices

  • Always verify the current group ownership of a file or directory before making changes.
  • Use chown to change both user and group ownership at once, if needed.
  • Regularly review and update group membership to ensure proper access control.