Changing File Ownership

To change the ownership of a file, you can use the chown command. The structure of this command is as follows:

chown {user|.group} file

For example, to make linda the owner of user root's file in the previous example, you must use the command chown linda rootsfile. To change the group owner of somefile to the group sales, you can use the command chown .sales somefile. It is also possible to change the ownership of a user and a group with one command, separating the user and group with a dot or colon. Note that for changing group ownership, you can use the command chgrp. Therefore, chown .sales somefile will do the same thing as chgrp sales somefile. Note that when using chgrp, you do not need to precede the name of the group with a dot.

Note If you are using chown to change group ownership, make sure you precede the name of the group with a dot or a colon. Otherwise, the chown command will think it is a user. You could, of course, use chgrp instead.

By default, chown and chgrp apply only to the file or directory on which they are used. You can, however, use the commands to work recursively as well; for example, chown -R linda somedir will make user linda the owner of all the files in somedir and all the subdirectories of somedir.

Was this article helpful?

0 0

Post a comment