Linux/Unix: How To Use Chown Command To Change Ownership

In this post, you’ll see how to change the owner and group of files, directories and links using chown command. How to use chown command to change file’s ownership to another user or another group.

chown command stands for “change file owner and group”. it can change the user or group ownership for each given file or directory. If you only provide an a user name, just owner will be change for that given file, and the file’s group is not changed. so if you give a user name followed by a colon and a group name, this is, owner and group ownership are changed. see also below’s chown syntax:

chown [options] username:groupname file

chown [options] username file

chown [options]  :groupname file

Let’s give some examples:

1. set the owner of file ddd.txt to user tom

[root@localhost osetc]# touch ddd.txt

[root@localhost osetc]# ls -l

-rw-r--r-- 1 root root 0 12-13 20:14 ddd.txt

[root@localhost osetc]# chown tom ddd.txt

[root@localhost osetc]# ls -l

-rw-r--r-- 1 tom root 0 12-13 20:14 ddd.txt

2. set the new group of file ddd.txt to group tom

[root@localhost osetc]# chown :tom ddd.txt

[root@localhost osetc]# ls -l

-rw-r--r-- 1 tom tom 0 12-13 20:14 ddd.txt

3. set user and group ownership of file ddd.txt to another user and group “mtest”

[root@localhost osetc]# ls -l ddd.txt

-rw-r--r-- 1 tom tom 0 12-13 20:14 ddd.txt

[root@localhost osetc]# chown mtest:mtest ddd.txt

[root@localhost osetc]# ls -l ddd.txt

-rw-r--r-- 1 mtest mtest 0 12-13 20:14 ddd.txt

If you want to change ownship of the directlry recursively, pls use “-R” option and then all files and subdirectories ownership will be changed.

See Also:

done..

 

You might also like:

Sidebar



back to top