The chgrp command in Linux is used to change the group ownership of a file or directory. Unlike chown, which can change both user and group, chgrp focuses exclusively on group ownership, making it the preferred tool for managing shared folder permissions without affecting individual file owners.
In Linux, every file has:
- an owner (user)
- a group
- permission bits for user, group, and others
The chgrp command modifies only the group, without affecting:
- the file owner
- existing permission bits
This makes chgrp ideal for:
- shared project directories
- multi-user environments
- fixing group ownership without touching user ownership
chgrp Command - Quick Cheat Sheet
| Task | Command |
|---|---|
| Change group ownership of a file | chgrp groupname filename |
| Change group ownership of multiple files | chgrp groupname file1 file2 file3 |
| Change group ownership of a directory | chgrp groupname directory |
| Change group ownership recursively | chgrp -R groupname directory |
| Change group recursively with verbose output | chgrp -Rv groupname directory |
| Change group only if current group matches | chgrp --from=oldgroup newgroup filename |
| Change group using reference file | chgrp --reference=referencefile filename |
| Change group using numeric GID | chgrp 1001 filename |
| Change group of symbolic link itself | chgrp -h groupname symlink |
| Display verbose output during operation | chgrp -v groupname filename |
| Display changes only when modification occurs | chgrp -c groupname filename |
| Suppress most error messages | chgrp -f groupname filename |
Prevent recursive operations on / | chgrp -R --preserve-root groupname /path |
Allow recursive operations on / | chgrp -R --no-preserve-root groupname /path |
| Change group for all files in current directory | chgrp groupname * |
| Change group ownership recursively for directory tree | chgrp -R groupname /var/www |
chgrp Command Examples Cheat Sheet (Printable)
Common usage patterns:
chgrp group file
chgrp group file1 file2
chgrp group directory
chgrp -R group directory
chgrp --reference=source target
chgrp -h group symlinkchgrp Command Syntax and Usage
Basic syntax
The general syntax of the chgrp command is:
chgrp [OPTION] GROUP FILEWhen operating on system files or files owned by other users, sudo
is typically required:
sudo chgrp GROUP FILEUsing group name vs GID
You can specify the target group in two ways.
Using group name (recommended)
This is the most readable and commonly used method:
sudo chgrp developers report.txtHere:
developersis the group namereport.txtis the target file
Using group ID (GID)
You can also use the numeric group ID:
sudo chgrp 1001 report.txtUsing GID is useful in scripts or automation, but group names are preferred for clarity and maintainability.
chgrp vs chown: Key Differences Explained
The chgrp and chown commands serve different purposes.
chgrp vs chown comparison
| Command | What it changes | Typical usage |
|---|---|---|
| chgrp | Group only | Shared files and directories |
| chown | User and group | Ownership transfer |
Example with chown:
sudo chown user:group file.txtExample with chgrp:
sudo chgrp group file.txtHow to Change Group Ownership Using chgrp
Change Group Ownership of a File
You can use the chgrp command to change the group ownership of one or
more files.
Single file example
To change the group ownership of a single file:
sudo chgrp developers report.txtAfter execution, the file report.txt will belong to the developers
group.
You can verify the change using:
ls -l report.txtMultiple files example
You can assign the same group to multiple files at once by listing them as arguments:
sudo chgrp developers file1.txt file2.txt file3.txtAll listed files will now share the same group ownership.
Change Group Ownership of a Directory
To change the group ownership of a directory:
sudo chgrp developers project_dirThis command changes the group ownership of the directory itself, but does not affect files inside the directory.
Use chgrp Recursively (With Safety Tips)
The recursive option allows chgrp to change the group ownership of a
directory and all its contents, including subdirectories and files.
Recursive directory change
To change group ownership recursively:
sudo chgrp -R developers project_dirThis command:
- changes the group of
project_dir - updates all files and subdirectories inside it
Recursive usage is common for:
- project folders
- shared team directories
- application deployment paths
--preserve-root explained
When using recursive operations with -R, the chgrp command can
operate on the root directory (/) if it is specified explicitly.
To prevent accidental modification of the entire filesystem, the
--preserve-root option can be used.
Example:
sudo chgrp -R --preserve-root developers /With this option enabled, the command will fail if / is specified
as the target directory.
By default, GNU chgrp uses --no-preserve-root, meaning the root
directory is not treated specially.
Copy Group Ownership From Another File (--reference)
Instead of specifying a group name, you can copy the group ownership from an existing file or directory.
Syntax:
sudo chgrp --reference=source_file target_filePractical automation example
This approach is useful in scripts where consistent group ownership is required.
Example:
sudo chgrp --reference=template.conf app.confHere:
template.confprovides the groupapp.confreceives the same group ownership
This avoids hardcoding group names and improves portability.
Change Group Ownership of Symbolic Links
Symbolic links behave differently from regular files when using chgrp.
Default behavior
By default, chgrp changes the group ownership of the target file
that the symbolic link points to, not the link itself.
Example:
sudo chgrp developers symlink_fileThe group ownership of the original file is changed.
--no-dereference (-h) explained
To change the group ownership of the symbolic link itself, use the
-h or --no-dereference option:
sudo chgrp -h developers symlink_fileThis ensures:
- only the symbolic link is modified
- the target file remains unchanged
This is useful when managing symbolic links in configuration directories or deployment setups.
Control chgrp Output (Verbose, Changes, Silent)
The chgrp command provides multiple options to control how much
information is displayed during execution.
Verbose mode (-v)
Displays information for every file processed, whether or not a change was made.
sudo chgrp -v developers file.txtUse this when you want full visibility of what chgrp is doing.
Changes only (-c)
Displays output only when a group change actually occurs.
sudo chgrp -c developers file.txtThis is useful in scripts or logs to avoid unnecessary output.
Silent mode (-f)
Suppresses most error messages.
sudo chgrp -f developers file.txtNote:
- Syntax errors or invalid group errors may still appear
- Useful when processing many files and ignoring non-critical failures
Frequently Asked Questions
1. What does the chgrp command do in Linux?
The chgrp command is used to change the group ownership of files and directories in Linux without modifying the file owner.2. What is the difference between chgrp and chown?
chgrp changes only the group ownership, whereas chown can change both user and group ownership of a file or directory.3. Does chgrp require sudo?
Yes, sudo is required when changing the group ownership of files not owned by the current user or when assigning a group the user is not a member of.4. How do I change group ownership recursively?
Use the -R or --recursive option with chgrp to change the group ownership of a directory and all its files and subdirectories.5. Does chgrp follow symbolic links?
By default, chgrp changes the group of the target file. Use -h or --no-dereference to change the group ownership of the symbolic link itself.Conclusion
The chgrp command is a safe and efficient way to manage group
ownership in Linux systems.
It is best suited for:
- shared directories
- team-based workflows
- permission management without changing file owners
By understanding recursive behavior, symbolic link handling, and proper
use of sudo, you can use chgrp confidently across Linux
distributions.

