How to Change Group Ownership Using chgrp

How to Change Group Ownership Using chgrp in Linux

Welcome to this Linux tutorial! Today, we’re going to learn how to use the chgrp command, which stands for “change group”.

In Linux, every file has an owner and a group. The group is important when you're sharing files with others who are in the same group.

Let’s say you have a file that you want to share with your team, and you want to change its group ownership to match your team’s group. That’s where chgrp comes in.

🔧 Step 1: Check the current group ownership

First, let’s create a sample file so we can experiment.

touch sample.txt
ls -l sample.txt
-rw-r--r-- 1 youruser yourgroup 0 Jul  2 10:00 sample.txt

Here, yourgroup is the current group. Let’s say we want to change it to a group called devteam.

👥 Step 2: Check if the group exists

getent group devteam
devteam:x:1002:alice,bob

If you don’t see output like this, you might need to ask your system admin to create the group or use sudo groupadd devteam if you have permissions.

🔁 Step 3: Change the group ownership using chgrp

sudo chgrp devteam sample.txt
ls -l sample.txt
-rw-r--r-- 1 youruser devteam 0 Jul  2 10:00 sample.txt

Now you can see the group has changed from yourgroup to devteam. Great job!

📁 Bonus: Change group ownership recursively for a directory

If you want to change group ownership for all files in a folder:

sudo chgrp -R devteam /path/to/folder

The -R flag stands for “recursive” and will apply the group change to all files and subdirectories.

✅ Summary

  • chgrp changes group ownership of files and directories
  • Use ls -l to check current ownership
  • Use sudo chgrp groupname filename to change group
  • Add -R for recursive changes on folders

That’s it! You’ve now learned how to change group ownership using chgrp in Linux. Practice it a few times, and you’ll be comfortable managing file permissions like a pro.

See you in the next tutorial!


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...