How to change ownership of a file
In our previous posts we saw how to change the permission on a file for different users. Now lets see how to change the ownership of a file. To change the ownership /group ownership of file or a directory we use chown command. Syntax for chown command is
chown [options] owner[:group] file
While using chown command if a single user id is given then that user will become owner of the given file/directory. If the owner is followed by a colon and group name then both owner and the group ownership will be changed
#1) To change the owner of a file, my_file, from guest to user calypso, execute
chown calypso my_file
#2) To change the ownership and group ownership of a file, my_file, to calypso and IT_Dept respectively, execute
chown calypso:IT_Dept my_file/
chown calypso:IT_Dept my_docs/
#3) To change the ownership of all the files and sub-directories inside a directory recursively, execute
chown -R calypso:IT_Dept my_docs/
#4) The permission of a file/directory can also be changed with reference to another file/directory. The below screen shot is such an example
For more options and details please refer the chown man pages
Comments
Post a Comment