Permission Command: How to use chgrp?

  • Post last modified:April 27, 2021
  • Reading time:2 mins read

This is the last article on permission command, we have explained you the chmod, chown, umask on how to use and when to use with precisely?

In chown article, we said the chgrp and chown both can use for changing ownership.

If you are new or you don’t know about chmod it advice you to go through the chmod first.

File Permission: What is chmod?

So,without further delay will start our topic.

What is chgrp?

In short and simple the chgrp command we use in the Linux system to change the group ownership of a file, folder, or directory.

chgrp stands for change group ownership, chgrp usually hands-on when we want to change the group of file or directory.

Syntax

chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...

If you want to know more options of chgrp

chgrp --help

Examples

How to use chgrp to change group permission?

If you want to change file or directory group then you can follow this

Syntax

chgrp [group-name] nameoffile

Now I’ll show you in my case you can see shen is the group

chgrp: Before group was shen
chgrp: Before group was shen

To change group in my case i’ll choose root as another group

$ sudo chgrp root nameofile 
chgrp: After group was root
chgrp: After group was root

Successfully, we have changed our group, Make sure to use sudo when you want to change group.

It is pretty simple command one more thing I’ll show you how to change ownership of a file or folder recursively

How to use recursively with chgrp command?

If you want to change group of the all directories or sub-directories that can be achieve by recursively method

Syntax

chgrp -R [group][directory-path]

Example

In this case all directories and files are under group of shen and we want to change group to root

chgrp: All Folder and file are under shen group
chgrp: All Folder and file are under shen group
$ sudo chgrp -R root ./

You can see the changes now all folders and files under root group.

chgrp: All Folder and file are under root group
chgrp: All Folder and file are under root group

Conclusion

Through the chgrp command, you change the group permission, It is similar to chown command comparatively it is easy to use.

Even there are many options that you can use along-with chgrp command.

If you having any difficulty, Question, or specific topic which you want we should explain then please share with us.

Like what you read? Please share it with others.
  • 1
    Share
guest
0 Comments
Inline Feedbacks
View all comments