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

Arunlal Ashok

Linux Server Administrator. I'm dealing with Linux servers since 2012. I started this blog to share and discuss my ideas with the world. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

You may also like...

1 Response

  1. February 1, 2014

    […] Links: chgrp, groupdel, groupmems, groupmod, useradd , usermod […]

Leave a Reply

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