How to change group ownership?

QuestionsQuestions8 SkillsProPermissions of FilesNov, 27 2025
097

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:

  1. Basic Syntax:

    chgrp new_group filename
  2. Example:
    To change the group ownership of a file named example.txt to a group called developers, 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.

  1. Basic Syntax:

    chown :new_group filename
  2. Example:
    To change the group ownership of example.txt to developers, 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.

  1. Using chgrp:

    chgrp -R new_group directory_name
  2. Using chown:

    chown -R :new_group directory_name

Summary:

  • Use chgrp new_group filename to change the group ownership of a specific file.
  • Use chown :new_group filename to achieve the same with the chown command.
  • Use the -R option to change group ownership recursively for directories and their contents.

0 Comments

no data
Be the first to share your comment!