The chown command can be used to change the user ownership as well as the group ownership of a file or directory. Initially, we will see how the chown command can be used to change file ownership. The syntax of the chown command is as follows:
$ chown <user_name_to_set_as_owner> <file_or_foldername>
The following are some the examples to illustrate the usage of the chown command:
List current ownership of file named myfile using the ls command is shown as follows:
$ ls -l myfile
Grant user ownership of the file named myfile to jack, as shown in the following screenshot:
The chown command is very often used with the -R option to recursively modify the ownership of a complete directory tree. The following command is used to grant ownership of a directory named mydir and all files and sub-directories within it to the user jack, as shown in the following screenshot: