How to Use the chgrp Command on Linux

Share
  • September 12, 2019

Fatmawati Achmad Zaenuri/Shutterstock.com

The chgrp command on Linux changes the group ownership of a file or directory. Why use it instead of chown ? Sometimes a Swiss Army knife is great, but when you really need a scalpel, only a scalpel will do.

When You Should Use chgrp

You use the chgrp command to change the group ownership of a file or directory. The chown command allows you to change the user owner and the group owner of a file or directory. So why would you need or use chgrp?

Well, for one thing, it’s easy. Using chown to change just the group owner setting is a little counterintuitive. You have to be very careful with the syntax. It hinges on the correct placing of a colon “:”. Misplace that, and you’re not making the change you thought you were.

The syntax of chgrp is altogether more straightforward. It also has a neat feature that tells you in simple terms what changes it has just made.

It is a purpose-built and dedicated tool for the task at hand. chgrp completely embraces the Unix design principle of doing one thing and doing it well. Let’s see what it has to offer.

Changing the Group Ownership of a File

To change the group ownership of a file is very straightforward. You must use sudo with chgrp. Groups are not owned by users, so whether a file or directory is moved from one group to another is not a decision that sits with the average user. That’s a job for someone with root privileges.

We’re going to change the group ownership of a C source file called “gc.c.” We’re going to change it to the “devteam” group.

We can check the current ownership values by using ls with the -l (long listing) option.

ls -l

Read the remaining 42 paragraphs

Source : How to Use the chgrp Command on Linux