Linux provides different tools for the similar or same functionality. chgrp
is the shortcuts for change group where used to change files group ownership. In this tutorial we will look different uses cases for chgrp
and examples. chgrp
provides similar functionality to chown
Syntax
Syntax is simple where we provide options , group name and files in a row.
chgrp OPTION GROUP FILES
Change File Group
We will start with a simple example where we will just just given file group. In this example we will change file named test
to the group named root
. We generally need root
privileges in order to change group. In this example we will use sudo
to get root
privilege.
$ sudo chgrp root test
Change File Group Recursively
Another useful use case for chgrp
is changing group ownership recursively. We will use -r
option for this operation. We will change the group to the ismail
in the directory named /home/ismail
recursively.
$ sudo chgrp -R ismail /home/ismail/
Change File Group Verbosely
While changing group we may need more information about the operation. We call this as verbose mode. We can see operations verbosely with the -v
option like below. In this example we will change directory named /home/ismail/.local
into group named ismail
recursively and print operations verbosely. We can see that if current file or folder is all ready assigned to the group we want to change we will get a message retained as
$ sudo chgrp -R -v ismail /home/ismail/.local/

Verbose Output Only Group Ownership Change
We may want to see verbose output only if the group ownership of a file or directory is changed. In this situation we can use -c
option. We will use previous example but only show changed files and folder. As we can see changed files will annotated with from root to ismail
which means groups ownership is changed from root to ismail.
$ sudo chgrp -R -c ismail /home/ismail/.local/
