chown command

LINUX-Frequently used commands

chown command Change the owner of a file
Syntax
chown   [Options] [User : Group] [File name]
The chown command is used to change the owner of a file to a specified user.
You can also specify ":group" after the user name to change the group name as well as the owner.
The user and group can be specified by name or ID, respectively.
The owner of the file will be the user who created the file.
Frequently used options
-R   Change the owner of all files under the specified directory.
-f    Do not display an error message if the owner could not be changed.
Example: Change the owner of a file.
$ su - ← become root
passwd  ←Enter the root password.
#  chown root:root /tmp/temp  ← Change the owner and group to root
#  ls -l  /tmp/temp
-rw-rw-r-- 1 root root 0 Jan 27 02:48 /tmp/temp  ← Owner and group become root
Example: Change the owner of files under a directory.
#  chown -R root:root  /tmp ← Change the owner and group of the files under the /tmp directory to root.
#  ls -l  /tmp
total 16
-rw-rw-r-- 1 root root 0 Jan 01 01:01 temp1.dat
-rw-rw-r-- 1 root root 0 Jan 01 01:01 temp2.dat
-rw-rw-r-- 1 root root 0 Jan 01 01:01 temp3.dat
-rw-rw-r-- 1 root root 0 Jan 01 01:01 temp4.dat
↑The owner and group of the files in the /tmp directory will be changed to root
Copied title and URL