Brief: This command is used to change the owner or group of a file
Syntax: chown username:groupname filename
Command: chown akash newFile.txt
Description:
If a file is owned by a user and needs to be changed to own it by other user then chown command can be used.
chown akash newFile.txt
The above command can be used to assign the ownership of file newFile.txt to a user with name akash.
The chown command can also be used to change the group of a file.
Suppose currently a file can be used by group of 'employeeGroup' and want to change it to be used by 'adminGroup' then below command will do
chmod :employeeGroup newFile.txt
User can also make use of the userid and groupid instead of username and group name.
For ex : chown 987:679 newFile.txt
Arguments:
-R : This paramter can be used to assign the owner to all the files within the sub directories of a current directory.
Important Examples:
1. changing the ownership of more then one file.
chown akash newfile1.txt newFile2.txt
chown akash:newgroup newfile1.txt newFile2.txt
2. changing the ownership recursively in all directories of mentioned directory.
chown -R akash /home/user/
3. Assigning the ownership to no user and no group(Not Recommanded)
chown nobody:nobody /home/user/newFile.txt