How to change the group of a file/directory – Unix/Linux

The owners of a file/dir under Linux are listed below:
1, Owner
2, Group
3, Others

You can change the group value of a file/dir by using the ‘chgrp’ command.
Syntax:

# chgrp newgroup file/dir 

Example:

[root@localhost ~]# ll crybit 
-rw-r--r--. 1 crybit root 0 Feb  1 05:01 crybit
[root@localhost ~]# chgrp crybit crybit
[root@localhost ~]# ll crybit 
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:01 crybit

Changed the group value from root to user crybit.

How to change the group value recursively?
You can use the switch ‘R’ to do the same:

Example:

[root@localhost ~]# cd dir/
[root@localhost dir]# ll
total 0
-rw-r--r--. 1 crybit root 0 Feb  1 05:09 a1.txt
-rw-r--r--. 1 crybit root 0 Feb  1 05:09 a2.txt
-rw-r--r--. 1 crybit root 0 Feb  1 05:09 a3.txt
-rw-r--r--. 1 crybit root 0 Feb  1 05:09 a4.txt
-rw-r--r--. 1 crybit root 0 Feb  1 05:09 a5.txt
[root@localhost dir]# cd -
/root
[root@localhost ~]# chgrp -R crybit dir/
[root@localhost ~]# cd -
/root/dir
[root@localhost dir]# ll
total 0
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:09 a1.txt
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:09 a2.txt
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:09 a3.txt
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:09 a4.txt
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:09 a5.txt

You can also use the chown command to change the group value.

How to change the owner and group value by using the chown command?
Syntax:

# chown owner:group file/dir
Or
# chown owner.group file/dir

Example:

[root@localhost ~]# ll crybit 
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:01 crybit
[root@localhost ~]# chown root.me crybit 
[root@localhost ~]# ll crybit 
-rw-r--r--. 1 root me 0 Feb  1 05:01 crybit

You can use the switch ‘R’ for changing recursively.

Simplest way to set same owner and group value for a file/dir?
Syntax:

# chown owner. file/dir

You can use the switch ‘R’ for doing recursively.

Example:

[root@localhost ~]# ll crybit 
-rw-r--r--. 1 root me 0 Feb  1 05:01 crybit
[root@localhost ~]# chown root. crybit
[root@localhost ~]# ll crybit 
-rw-r--r--. 1 root root 0 Feb  1 05:01 crybit

That’s it!! 🙂

Related Links:
chown, groupdel, groupmems, groupmod, useradd , usermod .

More:
ls, head, tail, top, ps, find, crontab

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

4 thoughts on “How to change the group of a file/directory – Unix/Linux

Leave a Reply

Your email address will not be published. Required fields are marked *