Home Linux How to change owner or group of files/directory in linux

How to change owner or group of files/directory in linux

Key Points:

1. I am new on Linux, want to change owner/group of files/directory in linux
2. Change the group of the directory recursively.

1. How to change owner of the file/directory

Let’s see the example of a centos directory.
Here owner is “arun” user. Now we will change this owner to user “unix

Change owner of centos directory
Change owner of centos directory

Remember here I am using sudo user or if you are using root user then do not need to use sudo prefix. To change owner to the new username “unix”, will use the following command with syntax.

#chown new_owner_name directory_name

[arun@localhost ~]$ sudo  chown  unix   centos/
chown command in linux
chown command in linux

Recursively change owner of directory: To recursively change owner of the directory or file, use this syntax:

# chown -R new_owner_name directory_name

[arun@localhost ~]$ sudo  chown  -R  unix   centos/

2. Change group of directory in linux

We are also going to change group of the ‘centos’ directory to group name ‘unix’. The syntax to change the group of file or directory is :

#chgrp new_group_name directory_name

[arun@localhost ~]$ sudo  chgrp   unix   centos/
chgrp command in linux
chgrp command in linux

Recursively change group of directory: Run this command on parent directory and subfolders group name will also changed.

Syntax is: sudo  chgrp   -R   new_group_name directory_name

 [arun@localhost ~]$ sudo  chgrp   -R   unix    centos/ 



Perfect !!! You have learned how to change owner and group of a file or directory.


2 COMMENTS

  1. Hello there I am so grateful I found your webpage, I really found you by mistake, while I was browsing on Digg for something else, Anyways I am here now and would just like to say thank you for a fantastic post and an all round thrilling blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the awesome work.

LEAVE A REPLY

Please enter your comment!
Please enter your name here