• Uncategorized
  • 1

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

Arunlal Ashok

Sr. Linux Server Administrator. I'm managing Linux servers since 2012. I started this blog to share and discuss my ideas. Check My Profile in uPwork (oDesk) and create a job, if you need any administration help. 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 *