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:

[[email protected] ~]# ll crybit 
-rw-r--r--. 1 crybit root 0 Feb  1 05:01 crybit
[[email protected] ~]# chgrp crybit crybit
[[email protected] ~]# 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:

[[email protected] ~]# cd dir/
[[email protected] 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
[[email protected] dir]# cd -
/root
[[email protected] ~]# chgrp -R crybit dir/
[[email protected] ~]# cd -
/root/dir
[[email protected] 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:

[[email protected] ~]# ll crybit 
-rw-r--r--. 1 crybit crybit 0 Feb  1 05:01 crybit
[[email protected] ~]# chown root.me crybit 
[[email protected] ~]# 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:

[[email protected] ~]# ll crybit 
-rw-r--r--. 1 root me 0 Feb  1 05:01 crybit
[[email protected] ~]# chown root. crybit
[[email protected] ~]# 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 Ashok

Operations Engineer at Endurance International Group. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team CryBit.com
We like to travel. Our travelogues are published at Trip Mentor

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 *