Skip to content

chgrp Linux Command Guide

The chgrp command in Linux is used to change the group ownership of files and directories. It allows users to assign a new group to a specified file or directory. By utilizing the chgrp command, you can easily modify the group ownership of multiple files at once, streamlining group management tasks. This command is especially useful in a shared working environment where users may need to collaborate on files within the same group.

Terminal window
chgrp [options] group file
OptionDescription
-cReport only when a change is made
-fSilence most error messages
-hChange the group of symbolic links only (default behavior)
-RRecursively change group of directories and their contents
—reference=reference_fileSet group to that of reference_file
—dereferenceAffect symlinks instead of references
—no-dereferenceAffect references instead of symlinks
—preserve-rootFail to operate recursively on ’/‘
ParameterDescription
groupThe group to which to change ownership to
fileThe file or directory to change the group ownership of
Terminal window
chgrp staff file.txt

Changes the group ownership of the file “file.txt” to the group “staff”.

Terminal window
chgrp -R admin documents/

Changes the group ownership of all files and subdirectories in the “documents” directory to the group “admin” recursively.

Terminal window
chgrp -v users file.txt

Displays verbose output when changing the group ownership of the file “file.txt” to the group “users”.

Terminal window
chgrp --preserve-root wheel /

Changes the group ownership of the root directory (”/”) to the group “wheel” while preserving the root directory permissions.

Section titled “Change Group Ownership for a Symbolic Link”
Terminal window
chgrp games game_link

Changes the group ownership of a symbolic link named “game_link” to the group “games”.

Change Group Ownership Using Numeric Group ID

Section titled “Change Group Ownership Using Numeric Group ID”
Terminal window
chgrp 1001 data.csv

Changes the group ownership of the file “data.csv” to the group ID “1001”.

Change Group Ownership using Symbolic Reference

Section titled “Change Group Ownership using Symbolic Reference”
Terminal window
chgrp :finance file.txt

Changes the group ownership of the file “file.txt” to the group “finance” using the symbolic reference.

To use the chgrp command in Linux, execute the following command:

Terminal window
chgrp newgroup file.txt

How do I change the group ownership recursively with chgrp?

Section titled “How do I change the group ownership recursively with chgrp?”

To change the group ownership recursively for all files and directories within a specified directory, use the recursive flag (-R) with chgrp:

Terminal window
chgrp -R newgroup directory

How can I specify a specific group by GID with chgrp?

Section titled “How can I specify a specific group by GID with chgrp?”

To change the group ownership of a file to a specific group identified by its Group ID (GID), use the numeric group ID with the chgrp command:

Terminal window
chgrp :1000 file.txt

How do I preserve the original file’s group with chgrp?

Section titled “How do I preserve the original file’s group with chgrp?”

To avoid changing the group ownership of a file while modifying its permissions, use the —reference option with chgrp to copy the group from a reference file:

Terminal window
chgrp --reference=referencefile file.txt

How can I display verbose output while using chgrp in Linux?

Section titled “How can I display verbose output while using chgrp in Linux?”

To display detailed information about the group changes being made by the chgrp command, use the verbose flag (-v) along with the command:

Terminal window
chgrp -v newgroup file.txt
Section titled “How do I change the group ownership without following symbolic links with chgrp?”

To change the group ownership of a symbolic link itself without following the link to the target file, use the —no-dereference option with chgrp:

Terminal window
chgrp --no-dereference newgroup symlink
  • Change the group ownership of a file or directory
  • Change the group ownership of multiple files or directories
  • Recursively change the group ownership of a directory and its contents