Linux command chown which stands for change owner,it’s used to change the user and/or group ownership for give file.

Syntax

chown name_of_new_owner file_name

OR

chown newuser:newgroup file_name

change file owner using chown command

sudo chown new_owner file_name

Below example change the owner of file file01 to root

j@ubuntu2004:~/tmp$ ls -l file01
-rw-rw-r-- 1 j j 0 Aug  2 07:35 file01
j@ubuntu2004:~/tmp$ sudo chown root file01
j@ubuntu2004:~/tmp$ ls -l file01
-rw-rw-r-- 1 root j 0 Aug  2 07:35 file01

sudo chown -R to change ownership recursively

For example ,change the owner:group to root:root for directory dir01

j@ubuntu2004:~/tmp$ ls -l dir01
total 0
-rw-rw-r-- 1 j j 0 Aug  2 07:26 1
-rw-rw-r-- 1 j j 0 Aug  2 07:26 2
-rw-rw-r-- 1 j j 0 Aug  2 07:26 a
-rw-rw-r-- 1 j j 0 Aug  2 07:26 b
j@ubuntu2004:~/tmp$ 
j@ubuntu2004:~/tmp$ sudo chown -R root:root dir01
[sudo] password for j: 
j@ubuntu2004:~/tmp$ ls -l dir01
total 0
-rw-rw-r-- 1 root root 0 Aug  2 07:26 1
-rw-rw-r-- 1 root root 0 Aug  2 07:26 2
-rw-rw-r-- 1 root root 0 Aug  2 07:26 a
-rw-rw-r-- 1 root root 0 Aug  2 07:26 b
j@ubuntu2004:~/tmp$
  • -R : Recursively
  • first root : user name
  • second root : group name

More sudo chown examples

sudo chown root /u

Change the owner of /u to “root”


sudo chown root:staff /u

Likewise, but also change its group to “staff”.


sudo chown -hR root /u

Change the owner of /u and subfiles to “root”