The chown command changes ownership (user or group) of files and directories in a Linux filesystem. Linux is designed to support a large number of users. Because of this, it needs to keep careful track of who is allowed to access a file, and how they can access it. These access rules are called permissions.
There are three major types of file permissions:
When a file is created, its owner is the user who created it, and the owning group is the user's current group.
The sytnax is:
chown owner-user file
chown owner-user:owner-group file
chown owner-user:owner-group directory
chown options owner-user:owner-group file
The user and group to own the file are separated by a colon, with no spaces in between. If the user is omitted, then the group must be preceded by a colon. Only root can change the owner of a file. The owner cannot transfer ownership, unless the owner is root, or uses sudo to run the command.
-R : Recursively change ownership of directories and their contents.
For example, you create a file, myfile.txt, which is owned by root. However, you intend the file to be used by your regular user account, myuser. To change the owner:
chown myuser myfile.txt