Account
Categories

chgrp command


Definition:

chgrp stands for Change Group.

When you make a file or folder for your project, you might need to assign which group can access it.

With this command, you can set which group owns the file or folder, without affecting the owner.

This way, you control which group of users can access or manage the file/folder.


Example:

In your project, there are 5 people:

  • You → the owner
  • One person → a user
  • The rest → a group

Using chgrp, you decide which group can access a file or folder. (Owner and permissions remain the same.)


Syntax:

chgrp [options] group filename

Options:

-R → Recursive

It changes the group of a folder and everything inside it, including all files and subfolders.


Parameters:

  • Group → Group of the file/folder
  • filename → Name of the file or folder

Step-by-Step Guide to Set Group Using chgrp

Step 1: Open your terminal.

Step 2: Type sudo before the chgrp command. You can use it to decide which group should have access to a file or folder.

Step 3: After entering this command, choose the group to assign. Example:

sudo chgrp developers file.txt

Here, developers are set as the group that can use the file.

Step 4: To change the group of a folder and everything inside it, use the -R option:

sudo chgrp -R developers myfolder

-R means all files and subfolders inside the folder will also get the new group.

Step 5: Check the group to confirm the change using:

ls -l

After typing this command, it will show a list of files and folders along with their owner, group, and other details.