How to change owner and group to a file

Before you try the codes below remember that these commands can only be used by the owner of the files or by root.

To change the owner of a file or a directory type:

#change owner to a file
chown username file

#change owner to a directory
chown username directory

To change the group to a file or a directory type:

#change group to a file
chgrp group file

#change group to a directory
chgrp group directory

Recursive and Verbose

To change the owner of a directory and of all its content and subfolders, type:

chown -R username directory

You can also use the -v parameter for verbose mode as follow:

chown -Rv username directory

The above parameters are valid also for chgrp, that is used to change group.

Random Posts

Previous Posts