Using chgrp Command In Linux [Examples]

chgrp command in Linux is a way allowing users to change group ownership of a file(s) or directory(ies). Actually, the files or directories in Linux operating system system is technically belong to an owner or group. And in order to alter or modify owner or grop according to requirements, chgroup command is used. in order to set the ownership of files or directories, chown command is used.

Syntax to use chgrp command

chgrp [OPTION]… GROUP_File_Name
chgrp [OPTION]… –reference=RFILE_Name
Important Note: In order to add or delete groups, it's recommended to use sudo or root access enabled users. so, if you are logged in as root, just run the command, else use sudo before the command as usual.

Options available to use with chgrp command

  • -c | -changes: Used for describing action for each file for which the group actually changes.
  • -f: Used for suppressing error messages
  • -v: Used to describe the action or non action forevery file.
  • –dereference/ –no-dereference: Used for altering group name of link files.
Also Read:   Using chpasswd Command In Linux [Examples]

Examples of chgrp command in Linux

1: Changing group ownership of a file servo.txt

sudo chgrp admin servo.txt

2: Changing group ownership of a directory servo

sudo chgrp admin servo

3: Chanignig group ownership of a directory and its content

sudo chgrp -R admin servo

4: Changing group name of a file or directory using another file as reference

sudo chgrp -R --reference=servo.txt servo

Nishant

Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.