To change the group ownership of a file or directory in Linux, you can use the chgrp command or the chown command with the appropriate syntax. Here are the methods:
Using chgrp Command:
-
Basic Syntax:
chgrp new_group filename -
Example:
To change the group ownership of a file namedexample.txtto a group calleddevelopers, you would run:chgrp developers example.txt
Using chown Command:
You can also change the group ownership using the chown command by specifying the group after a colon.
-
Basic Syntax:
chown :new_group filename -
Example:
To change the group ownership ofexample.txttodevelopers, you would run:chown :developers example.txt
Changing Group Ownership Recursively:
If you want to change the group ownership of a directory and all its contents, you can use the -R (recursive) option with either command.
-
Using
chgrp:chgrp -R new_group directory_name -
Using
chown:chown -R :new_group directory_name
Summary:
- Use
chgrp new_group filenameto change the group ownership of a specific file. - Use
chown :new_group filenameto achieve the same with thechowncommand. - Use the
-Roption to change group ownership recursively for directories and their contents.
